Add a direction argument to socket upcalls, so they can tell why they've

been called when, for example, they're waiting for space to write.  From
Ritesh Agrawal at Coyote Point.
This commit is contained in:
tls 2009-09-02 14:56:57 +00:00
parent d90bf6dc81
commit fd671f648a
5 changed files with 28 additions and 27 deletions

@ -1,4 +1,4 @@
/* $NetBSD: uipc_socket2.c,v 1.103 2009/07/24 01:09:49 christos Exp $ */
/* $NetBSD: uipc_socket2.c,v 1.104 2009/09/02 14:56:57 tls Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -58,7 +58,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.103 2009/07/24 01:09:49 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_socket2.c,v 1.104 2009/09/02 14:56:57 tls Exp $");
#include "opt_mbuftrace.h"
#include "opt_sb_max.h"
@ -190,7 +190,8 @@ soisconnected(struct socket *so)
so->so_upcallarg = head->so_accf->so_accept_filter_arg;
so->so_rcv.sb_flags |= SB_UPCALL;
so->so_options &= ~SO_ACCEPTFILTER;
(*so->so_upcall)(so, so->so_upcallarg, M_DONTWAIT);
(*so->so_upcall)(so, so->so_upcallarg,
POLLIN|POLLRDNORM, M_DONTWAIT);
}
} else {
cv_broadcast(&so->so_cv);
@ -472,7 +473,7 @@ sowakeup(struct socket *so, struct sockbuf *sb, int code)
if (sb->sb_flags & SB_ASYNC)
fownsignal(so->so_pgid, SIGIO, code, band, so);
if (sb->sb_flags & SB_UPCALL)
(*so->so_upcall)(so, so->so_upcallarg, M_DONTWAIT);
(*so->so_upcall)(so, so->so_upcallarg, band, M_DONTWAIT);
}
/*

@ -1,4 +1,4 @@
/* $NetBSD: if_gre.c,v 1.140 2009/04/28 23:05:25 dyoung Exp $ */
/* $NetBSD: if_gre.c,v 1.141 2009/09/02 14:56:57 tls Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.140 2009/04/28 23:05:25 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.141 2009/09/02 14:56:57 tls Exp $");
#include "opt_atalk.h"
#include "opt_gre.h"
@ -419,7 +419,7 @@ gre_clone_destroy(struct ifnet *ifp)
}
static void
gre_receive(struct socket *so, void *arg, int waitflag)
gre_receive(struct socket *so, void *arg, int events, int waitflag)
{
struct gre_softc *sc = (struct gre_softc *)arg;
int rc;

@ -1,4 +1,4 @@
/* $NetBSD: accf_data.c,v 1.5 2008/11/20 10:22:11 ad Exp $ */
/* $NetBSD: accf_data.c,v 1.6 2009/09/02 14:56:57 tls Exp $ */
/*-
* Copyright (c) 2000 Alfred Perlstein <alfred@FreeBSD.org>
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: accf_data.c,v 1.5 2008/11/20 10:22:11 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: accf_data.c,v 1.6 2009/09/02 14:56:57 tls Exp $");
#define ACCEPT_FILTER_MOD
@ -44,7 +44,7 @@ MODULE(MODULE_CLASS_MISC, accf_dataready, NULL);
/* accept filter that holds a socket until data arrives */
static void sohasdata(struct socket *so, void *arg, int waitflag);
static void sohasdata(struct socket *so, void *arg, int events, int waitflag);
static struct accept_filter accf_data_filter = {
.accf_name = "dataready",
@ -77,7 +77,7 @@ accf_dataready_modcmd(modcmd_t cmd, void *arg)
}
static void
sohasdata(struct socket *so, void *arg, int waitflag)
sohasdata(struct socket *so, void *arg, int events, int waitflag)
{
if (!soreadable(so))

@ -1,4 +1,4 @@
/* $NetBSD: accf_http.c,v 1.6 2008/11/21 16:08:57 joerg Exp $ */
/* $NetBSD: accf_http.c,v 1.7 2009/09/02 14:56:57 tls Exp $ */
/*-
* Copyright (c) 2000 Paycounter, Inc.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: accf_http.c,v 1.6 2008/11/21 16:08:57 joerg Exp $");
__KERNEL_RCSID(0, "$NetBSD: accf_http.c,v 1.7 2009/09/02 14:56:57 tls Exp $");
#define ACCEPT_FILTER_MOD
@ -46,11 +46,11 @@ __KERNEL_RCSID(0, "$NetBSD: accf_http.c,v 1.6 2008/11/21 16:08:57 joerg Exp $");
MODULE(MODULE_CLASS_MISC, accf_httpready, NULL);
/* check for GET/HEAD */
static void sohashttpget(struct socket *so, void *arg, int waitflag);
static void sohashttpget(struct socket *so, void *arg, int events, int waitflag);
/* check for HTTP/1.0 or HTTP/1.1 */
static void soparsehttpvers(struct socket *so, void *arg, int waitflag);
static void soparsehttpvers(struct socket *so, void *arg, int events, int waitflag);
/* check for end of HTTP/1.x request */
static void soishttpconnected(struct socket *so, void *arg, int waitflag);
static void soishttpconnected(struct socket *so, void *arg, int events, int waitflag);
/* strcmp on an mbuf chain */
static int mbufstrcmp(struct mbuf *m, struct mbuf *npkt, int offset, const char *cmp);
/* strncmp on an mbuf chain */
@ -221,7 +221,7 @@ mbufstrncmp(struct mbuf *m, struct mbuf *npkt, int offset, int len, const char *
} while(0)
static void
sohashttpget(struct socket *so, void *arg, int waitflag)
sohashttpget(struct socket *so, void *arg, int events, int waitflag)
{
if ((so->so_state & SS_CANTRCVMORE) == 0 && !sbfull(&so->so_rcv)) {
@ -255,9 +255,9 @@ sohashttpget(struct socket *so, void *arg, int waitflag)
if (mbufstrcmp(m, m->m_nextpkt, 1, cmp) == 1) {
DPRINT("mbufstrcmp ok");
if (parse_http_version == 0)
soishttpconnected(so, arg, waitflag);
soishttpconnected(so, arg, events, waitflag);
else
soparsehttpvers(so, arg, waitflag);
soparsehttpvers(so, arg, events, waitflag);
return;
}
DPRINT("mbufstrcmp bad");
@ -272,7 +272,7 @@ fallout:
}
static void
soparsehttpvers(struct socket *so, void *arg, int waitflag)
soparsehttpvers(struct socket *so, void *arg, int events, int waitflag)
{
struct mbuf *m, *n;
int i, cc, spaces, inspaces;
@ -325,7 +325,7 @@ soparsehttpvers(struct socket *so, void *arg, int waitflag)
mbufstrcmp(m, n, i, "HTTP/1.1")) {
DPRINT("ok");
soishttpconnected(so,
arg, waitflag);
arg, events, waitflag);
return;
} else {
DPRINT("bad");
@ -357,7 +357,7 @@ fallout:
#define NCHRS 3
static void
soishttpconnected(struct socket *so, void *arg, int waitflag)
soishttpconnected(struct socket *so, void *arg, int events, int waitflag)
{
char a, b, c;
struct mbuf *m, *n;

@ -1,4 +1,4 @@
/* $NetBSD: socketvar.h,v 1.119 2009/04/04 10:12:52 ad Exp $ */
/* $NetBSD: socketvar.h,v 1.120 2009/09/02 14:56:57 tls Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -159,7 +159,7 @@ struct socket {
struct sockbuf so_rcv; /* receive buffer */
void *so_internal; /* Space for svr4 stream data */
void (*so_upcall) (struct socket *, void *, int);
void (*so_upcall) (struct socket *, void *, int, int);
void * so_upcallarg; /* Arg for above */
int (*so_send) (struct socket *, struct mbuf *,
struct uio *, struct mbuf *,
@ -214,11 +214,11 @@ do { \
struct accept_filter {
char accf_name[16];
void (*accf_callback)
(struct socket *so, void *arg, int waitflag);
(struct socket *, void *, int, int);
void * (*accf_create)
(struct socket *so, char *arg);
(struct socket *, char *);
void (*accf_destroy)
(struct socket *so);
(struct socket *);
LIST_ENTRY(accept_filter) accf_next;
u_int accf_refcnt;
};