version 1.64, 2002/05/02 17:55:51 |
version 1.78, 2003/02/26 06:31:11 |
Line 91 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 91 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/signalvar.h> |
#include <sys/signalvar.h> |
#include <sys/resourcevar.h> |
#include <sys/resourcevar.h> |
#include <sys/pool.h> |
#include <sys/pool.h> |
|
#include <sys/event.h> |
|
|
#include <uvm/uvm.h> |
#include <uvm/uvm.h> |
|
|
struct pool socket_pool; |
struct pool socket_pool; |
|
|
|
MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options"); |
|
MALLOC_DEFINE(M_SONAME, "soname", "socket name"); |
|
|
extern int somaxconn; /* patchable (XXX sysctl) */ |
extern int somaxconn; /* patchable (XXX sysctl) */ |
int somaxconn = SOMAXCONN; |
int somaxconn = SOMAXCONN; |
|
|
|
|
#endif /* SOSEND_COUNTERS */ |
#endif /* SOSEND_COUNTERS */ |
} |
} |
|
|
#ifdef SOSEND_LOAN |
#ifdef SOSEND_NO_LOAN |
|
int use_sosend_loan = 0; |
|
#else |
|
int use_sosend_loan = 1; |
|
#endif |
|
|
struct mbuf *so_pendfree; |
struct mbuf *so_pendfree; |
|
|
Line 146 int sokvawaiters; |
|
Line 154 int sokvawaiters; |
|
#define SOCK_LOAN_CHUNK 65536 |
#define SOCK_LOAN_CHUNK 65536 |
|
|
static void |
static void |
sodoloanfree(caddr_t buf, u_int size) |
sodoloanfree(caddr_t buf, size_t size) |
{ |
{ |
struct vm_page **pgs; |
struct vm_page **pgs; |
vaddr_t va, sva, eva; |
vaddr_t va, sva, eva; |
Line 216 sodopendfree(struct socket *so) |
|
Line 224 sodopendfree(struct socket *so) |
|
} |
} |
|
|
static void |
static void |
soloanfree(struct mbuf *m, caddr_t buf, u_int size, void *arg) |
soloanfree(struct mbuf *m, caddr_t buf, size_t size, void *arg) |
{ |
{ |
struct socket *so = arg; |
struct socket *so = arg; |
int s; |
int s; |
Line 303 sosend_loan(struct socket *so, struct ui |
|
Line 311 sosend_loan(struct socket *so, struct ui |
|
return (space); |
return (space); |
} |
} |
|
|
#endif /* SOSEND_LOAN */ |
|
|
|
/* |
/* |
* Socket operation routines. |
* Socket operation routines. |
* These routines are called by the routines in |
* These routines are called by the routines in |
Line 339 socreate(int dom, struct socket **aso, i |
|
Line 345 socreate(int dom, struct socket **aso, i |
|
so->so_proto = prp; |
so->so_proto = prp; |
so->so_send = sosend; |
so->so_send = sosend; |
so->so_receive = soreceive; |
so->so_receive = soreceive; |
|
#ifdef MBUFTRACE |
|
so->so_rcv.sb_mowner = &prp->pr_domain->dom_mowner; |
|
so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; |
|
so->so_mowner = &prp->pr_domain->dom_mowner; |
|
#endif |
if (p != 0) |
if (p != 0) |
so->so_uid = p->p_ucred->cr_uid; |
so->so_uid = p->p_ucred->cr_uid; |
error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, |
error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, |
Line 390 solisten(struct socket *so, int backlog) |
|
Line 401 solisten(struct socket *so, int backlog) |
|
void |
void |
sofree(struct socket *so) |
sofree(struct socket *so) |
{ |
{ |
#ifdef SOSEND_LOAN |
|
struct mbuf *m; |
struct mbuf *m; |
#endif |
|
|
|
if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) |
if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) |
return; |
return; |
Line 407 sofree(struct socket *so) |
|
Line 416 sofree(struct socket *so) |
|
} |
} |
sbrelease(&so->so_snd); |
sbrelease(&so->so_snd); |
sorflush(so); |
sorflush(so); |
#ifdef SOSEND_LOAN |
|
while ((m = so->so_pendfree) != NULL) { |
while ((m = so->so_pendfree) != NULL) { |
so->so_pendfree = m->m_next; |
so->so_pendfree = m->m_next; |
m->m_next = so_pendfree; |
m->m_next = so_pendfree; |
so_pendfree = m; |
so_pendfree = m; |
} |
} |
#endif |
|
pool_put(&socket_pool, so); |
pool_put(&socket_pool, so); |
} |
} |
|
|
Line 569 sodisconnect(struct socket *so) |
|
Line 576 sodisconnect(struct socket *so) |
|
(struct proc *)0); |
(struct proc *)0); |
bad: |
bad: |
splx(s); |
splx(s); |
#ifdef SOSEND_LOAN |
|
sodopendfree(so); |
sodopendfree(so); |
#endif |
|
return (error); |
return (error); |
} |
} |
|
|
Line 602 sosend(struct socket *so, struct mbuf *a |
|
Line 607 sosend(struct socket *so, struct mbuf *a |
|
long space, len, resid, clen, mlen; |
long space, len, resid, clen, mlen; |
int error, s, dontroute, atomic; |
int error, s, dontroute, atomic; |
|
|
#ifdef SOSEND_LOAN |
|
sodopendfree(so); |
sodopendfree(so); |
#endif |
|
|
|
p = curproc; /* XXX */ |
p = curproc; /* XXX */ |
clen = 0; |
clen = 0; |
Line 683 sosend(struct socket *so, struct mbuf *a |
|
Line 686 sosend(struct socket *so, struct mbuf *a |
|
top->m_flags |= M_EOR; |
top->m_flags |= M_EOR; |
} else do { |
} else do { |
if (top == 0) { |
if (top == 0) { |
MGETHDR(m, M_WAIT, MT_DATA); |
m = m_gethdr(M_WAIT, MT_DATA); |
mlen = MHLEN; |
mlen = MHLEN; |
m->m_pkthdr.len = 0; |
m->m_pkthdr.len = 0; |
m->m_pkthdr.rcvif = (struct ifnet *)0; |
m->m_pkthdr.rcvif = (struct ifnet *)0; |
} else { |
} else { |
MGET(m, M_WAIT, MT_DATA); |
m = m_get(M_WAIT, MT_DATA); |
mlen = MLEN; |
mlen = MLEN; |
} |
} |
#ifdef SOSEND_LOAN |
MCLAIM(m, so->so_snd.sb_mowner); |
if (uio->uio_iov->iov_len >= SOCK_LOAN_THRESH && |
if (use_sosend_loan && |
|
uio->uio_iov->iov_len >= SOCK_LOAN_THRESH && |
space >= SOCK_LOAN_THRESH && |
space >= SOCK_LOAN_THRESH && |
(len = sosend_loan(so, uio, m, |
(len = sosend_loan(so, uio, m, |
space)) != 0) { |
space)) != 0) { |
Line 700 sosend(struct socket *so, struct mbuf *a |
|
Line 704 sosend(struct socket *so, struct mbuf *a |
|
space -= len; |
space -= len; |
goto have_data; |
goto have_data; |
} |
} |
#endif /* SOSEND_LOAN */ |
|
if (resid >= MINCLSIZE && space >= MCLBYTES) { |
if (resid >= MINCLSIZE && space >= MCLBYTES) { |
SOSEND_COUNTER_INCR(&sosend_copy_big); |
SOSEND_COUNTER_INCR(&sosend_copy_big); |
MCLGET(m, M_WAIT); |
m_clget(m, M_WAIT); |
if ((m->m_flags & M_EXT) == 0) |
if ((m->m_flags & M_EXT) == 0) |
goto nopages; |
goto nopages; |
mlen = MCLBYTES; |
mlen = MCLBYTES; |
Line 728 sosend(struct socket *so, struct mbuf *a |
|
Line 731 sosend(struct socket *so, struct mbuf *a |
|
} |
} |
error = uiomove(mtod(m, caddr_t), (int)len, |
error = uiomove(mtod(m, caddr_t), (int)len, |
uio); |
uio); |
#ifdef SOSEND_LOAN |
|
have_data: |
have_data: |
#endif |
|
resid = uio->uio_resid; |
resid = uio->uio_resid; |
m->m_len = len; |
m->m_len = len; |
*mp = m; |
*mp = m; |
Line 806 soreceive(struct socket *so, struct mbuf |
|
Line 807 soreceive(struct socket *so, struct mbuf |
|
int flags, len, error, s, offset, moff, type, orig_resid; |
int flags, len, error, s, offset, moff, type, orig_resid; |
struct protosw *pr; |
struct protosw *pr; |
struct mbuf *nextrecord; |
struct mbuf *nextrecord; |
|
int mbuf_removed = 0; |
#ifdef SOSEND_LOAN |
|
sodopendfree(so); |
|
#endif |
|
|
|
pr = so->so_proto; |
pr = so->so_proto; |
mp = mp0; |
mp = mp0; |
Line 823 soreceive(struct socket *so, struct mbuf |
|
Line 821 soreceive(struct socket *so, struct mbuf |
|
flags = *flagsp &~ MSG_EOR; |
flags = *flagsp &~ MSG_EOR; |
else |
else |
flags = 0; |
flags = 0; |
|
|
|
if ((flags & MSG_DONTWAIT) == 0) |
|
sodopendfree(so); |
|
|
if (flags & MSG_OOB) { |
if (flags & MSG_OOB) { |
m = m_get(M_WAIT, MT_DATA); |
m = m_get(M_WAIT, MT_DATA); |
error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m, |
error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m, |
Line 902 soreceive(struct socket *so, struct mbuf |
|
Line 904 soreceive(struct socket *so, struct mbuf |
|
error = EWOULDBLOCK; |
error = EWOULDBLOCK; |
goto release; |
goto release; |
} |
} |
|
SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 1"); |
|
SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 1"); |
sbunlock(&so->so_rcv); |
sbunlock(&so->so_rcv); |
error = sbwait(&so->so_rcv); |
error = sbwait(&so->so_rcv); |
splx(s); |
splx(s); |
Line 910 soreceive(struct socket *so, struct mbuf |
|
Line 914 soreceive(struct socket *so, struct mbuf |
|
goto restart; |
goto restart; |
} |
} |
dontblock: |
dontblock: |
|
/* |
|
* On entry here, m points to the first record of the socket buffer. |
|
* While we process the initial mbufs containing address and control |
|
* info, we save a copy of m->m_nextpkt into nextrecord. |
|
*/ |
#ifdef notyet /* XXXX */ |
#ifdef notyet /* XXXX */ |
if (uio->uio_procp) |
if (uio->uio_procp) |
uio->uio_procp->p_stats->p_ru.ru_msgrcv++; |
uio->uio_procp->p_stats->p_ru.ru_msgrcv++; |
#endif |
#endif |
|
KASSERT(m == so->so_rcv.sb_mb); |
|
SBLASTRECORDCHK(&so->so_rcv, "soreceive 1"); |
|
SBLASTMBUFCHK(&so->so_rcv, "soreceive 1"); |
nextrecord = m->m_nextpkt; |
nextrecord = m->m_nextpkt; |
if (pr->pr_flags & PR_ADDR) { |
if (pr->pr_flags & PR_ADDR) { |
#ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
Line 927 soreceive(struct socket *so, struct mbuf |
|
Line 939 soreceive(struct socket *so, struct mbuf |
|
m = m->m_next; |
m = m->m_next; |
} else { |
} else { |
sbfree(&so->so_rcv, m); |
sbfree(&so->so_rcv, m); |
|
mbuf_removed = 1; |
if (paddr) { |
if (paddr) { |
*paddr = m; |
*paddr = m; |
so->so_rcv.sb_mb = m->m_next; |
so->so_rcv.sb_mb = m->m_next; |
Line 945 soreceive(struct socket *so, struct mbuf |
|
Line 958 soreceive(struct socket *so, struct mbuf |
|
m = m->m_next; |
m = m->m_next; |
} else { |
} else { |
sbfree(&so->so_rcv, m); |
sbfree(&so->so_rcv, m); |
|
mbuf_removed = 1; |
if (controlp) { |
if (controlp) { |
if (pr->pr_domain->dom_externalize && |
if (pr->pr_domain->dom_externalize && |
mtod(m, struct cmsghdr *)->cmsg_type == |
mtod(m, struct cmsghdr *)->cmsg_type == |
Line 964 soreceive(struct socket *so, struct mbuf |
|
Line 978 soreceive(struct socket *so, struct mbuf |
|
controlp = &(*controlp)->m_next; |
controlp = &(*controlp)->m_next; |
} |
} |
} |
} |
|
|
|
/* |
|
* If m is non-NULL, we have some data to read. From now on, |
|
* make sure to keep sb_lastrecord consistent when working on |
|
* the last packet on the chain (nextrecord == NULL) and we |
|
* change m->m_nextpkt. |
|
*/ |
if (m) { |
if (m) { |
if ((flags & MSG_PEEK) == 0) |
if ((flags & MSG_PEEK) == 0) { |
m->m_nextpkt = nextrecord; |
m->m_nextpkt = nextrecord; |
|
/* |
|
* If nextrecord == NULL (this is a single chain), |
|
* then sb_lastrecord may not be valid here if m |
|
* was changed earlier. |
|
*/ |
|
if (nextrecord == NULL) { |
|
KASSERT(so->so_rcv.sb_mb == m); |
|
so->so_rcv.sb_lastrecord = m; |
|
} |
|
} |
type = m->m_type; |
type = m->m_type; |
if (type == MT_OOBDATA) |
if (type == MT_OOBDATA) |
flags |= MSG_OOB; |
flags |= MSG_OOB; |
|
} else { |
|
if ((flags & MSG_PEEK) == 0) { |
|
KASSERT(so->so_rcv.sb_mb == m); |
|
so->so_rcv.sb_mb = nextrecord; |
|
SB_EMPTY_FIXUP(&so->so_rcv); |
|
} |
} |
} |
|
SBLASTRECORDCHK(&so->so_rcv, "soreceive 2"); |
|
SBLASTMBUFCHK(&so->so_rcv, "soreceive 2"); |
|
|
moff = 0; |
moff = 0; |
offset = 0; |
offset = 0; |
while (m && uio->uio_resid > 0 && error == 0) { |
while (m && uio->uio_resid > 0 && error == 0) { |
Line 998 soreceive(struct socket *so, struct mbuf |
|
Line 1038 soreceive(struct socket *so, struct mbuf |
|
* block interrupts again. |
* block interrupts again. |
*/ |
*/ |
if (mp == 0) { |
if (mp == 0) { |
|
SBLASTRECORDCHK(&so->so_rcv, "soreceive uiomove"); |
|
SBLASTMBUFCHK(&so->so_rcv, "soreceive uiomove"); |
splx(s); |
splx(s); |
error = uiomove(mtod(m, caddr_t) + moff, (int)len, uio); |
error = uiomove(mtod(m, caddr_t) + moff, (int)len, uio); |
s = splsoftnet(); |
s = splsoftnet(); |
if (error) |
if (error) { |
|
/* |
|
* If any part of the record has been removed |
|
* (such as the MT_SONAME mbuf, which will |
|
* happen when PR_ADDR, and thus also |
|
* PR_ATOMIC, is set), then drop the entire |
|
* record to maintain the atomicity of the |
|
* receive operation. |
|
* |
|
* This avoids a later panic("receive 1a") |
|
* when compiled with DIAGNOSTIC. |
|
*/ |
|
if (m && mbuf_removed |
|
&& (pr->pr_flags & PR_ATOMIC)) |
|
(void) sbdroprecord(&so->so_rcv); |
|
|
goto release; |
goto release; |
|
} |
} else |
} else |
uio->uio_resid -= len; |
uio->uio_resid -= len; |
if (len == m->m_len - moff) { |
if (len == m->m_len - moff) { |
Line 1023 soreceive(struct socket *so, struct mbuf |
|
Line 1081 soreceive(struct socket *so, struct mbuf |
|
MFREE(m, so->so_rcv.sb_mb); |
MFREE(m, so->so_rcv.sb_mb); |
m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
} |
} |
if (m) |
/* |
|
* If m != NULL, we also know that |
|
* so->so_rcv.sb_mb != NULL. |
|
*/ |
|
KASSERT(so->so_rcv.sb_mb == m); |
|
if (m) { |
m->m_nextpkt = nextrecord; |
m->m_nextpkt = nextrecord; |
|
if (nextrecord == NULL) |
|
so->so_rcv.sb_lastrecord = m; |
|
} else { |
|
so->so_rcv.sb_mb = nextrecord; |
|
SB_EMPTY_FIXUP(&so->so_rcv); |
|
} |
|
SBLASTRECORDCHK(&so->so_rcv, "soreceive 3"); |
|
SBLASTMBUFCHK(&so->so_rcv, "soreceive 3"); |
} |
} |
} else { |
} else { |
if (flags & MSG_PEEK) |
if (flags & MSG_PEEK) |
Line 1063 soreceive(struct socket *so, struct mbuf |
|
Line 1134 soreceive(struct socket *so, struct mbuf |
|
!sosendallatonce(so) && !nextrecord) { |
!sosendallatonce(so) && !nextrecord) { |
if (so->so_error || so->so_state & SS_CANTRCVMORE) |
if (so->so_error || so->so_state & SS_CANTRCVMORE) |
break; |
break; |
|
/* |
|
* If we are peeking and the socket receive buffer is |
|
* full, stop since we can't get more data to peek at. |
|
*/ |
|
if ((flags & MSG_PEEK) && sbspace(&so->so_rcv) <= 0) |
|
break; |
|
/* |
|
* If we've drained the socket buffer, tell the |
|
* protocol in case it needs to do something to |
|
* get it filled again. |
|
*/ |
|
if ((pr->pr_flags & PR_WANTRCVD) && so->so_pcb) |
|
(*pr->pr_usrreq)(so, PRU_RCVD, |
|
(struct mbuf *)0, |
|
(struct mbuf *)(long)flags, |
|
(struct mbuf *)0, |
|
(struct proc *)0); |
|
SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2"); |
|
SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2"); |
error = sbwait(&so->so_rcv); |
error = sbwait(&so->so_rcv); |
if (error) { |
if (error) { |
sbunlock(&so->so_rcv); |
sbunlock(&so->so_rcv); |
Line 1080 soreceive(struct socket *so, struct mbuf |
|
Line 1170 soreceive(struct socket *so, struct mbuf |
|
(void) sbdroprecord(&so->so_rcv); |
(void) sbdroprecord(&so->so_rcv); |
} |
} |
if ((flags & MSG_PEEK) == 0) { |
if ((flags & MSG_PEEK) == 0) { |
if (m == 0) |
if (m == 0) { |
|
/* |
|
* First part is an inline SB_EMPTY_FIXUP(). Second |
|
* part makes sure sb_lastrecord is up-to-date if |
|
* there is still data in the socket buffer. |
|
*/ |
so->so_rcv.sb_mb = nextrecord; |
so->so_rcv.sb_mb = nextrecord; |
|
if (so->so_rcv.sb_mb == NULL) { |
|
so->so_rcv.sb_mbtail = NULL; |
|
so->so_rcv.sb_lastrecord = NULL; |
|
} else if (nextrecord->m_nextpkt == NULL) |
|
so->so_rcv.sb_lastrecord = nextrecord; |
|
} |
|
SBLASTRECORDCHK(&so->so_rcv, "soreceive 4"); |
|
SBLASTMBUFCHK(&so->so_rcv, "soreceive 4"); |
if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) |
if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) |
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
(struct mbuf *)(long)flags, (struct mbuf *)0, |
(struct mbuf *)(long)flags, (struct mbuf *)0, |
Line 1247 sosetopt(struct socket *so, int level, i |
|
Line 1350 sosetopt(struct socket *so, int level, i |
|
goto bad; |
goto bad; |
} |
} |
tv = mtod(m, struct timeval *); |
tv = mtod(m, struct timeval *); |
if (tv->tv_sec * hz + tv->tv_usec / tick > SHRT_MAX) { |
if (tv->tv_sec > (SHRT_MAX - tv->tv_usec / tick) / hz) { |
error = EDOM; |
error = EDOM; |
goto bad; |
goto bad; |
} |
} |
val = tv->tv_sec * hz + tv->tv_usec / tick; |
val = tv->tv_sec * hz + tv->tv_usec / tick; |
|
if (val == 0 && tv->tv_usec != 0) |
|
val = 1; |
|
|
switch (optname) { |
switch (optname) { |
|
|
Line 1375 sohasoutofband(struct socket *so) |
|
Line 1480 sohasoutofband(struct socket *so) |
|
psignal(p, SIGURG); |
psignal(p, SIGURG); |
selwakeup(&so->so_rcv.sb_sel); |
selwakeup(&so->so_rcv.sb_sel); |
} |
} |
|
|
|
static void |
|
filt_sordetach(struct knote *kn) |
|
{ |
|
struct socket *so; |
|
|
|
so = (struct socket *)kn->kn_fp->f_data; |
|
SLIST_REMOVE(&so->so_rcv.sb_sel.sel_klist, kn, knote, kn_selnext); |
|
if (SLIST_EMPTY(&so->so_rcv.sb_sel.sel_klist)) |
|
so->so_rcv.sb_flags &= ~SB_KNOTE; |
|
} |
|
|
|
/*ARGSUSED*/ |
|
static int |
|
filt_soread(struct knote *kn, long hint) |
|
{ |
|
struct socket *so; |
|
|
|
so = (struct socket *)kn->kn_fp->f_data; |
|
kn->kn_data = so->so_rcv.sb_cc; |
|
if (so->so_state & SS_CANTRCVMORE) { |
|
kn->kn_flags |= EV_EOF; |
|
kn->kn_fflags = so->so_error; |
|
return (1); |
|
} |
|
if (so->so_error) /* temporary udp error */ |
|
return (1); |
|
if (kn->kn_sfflags & NOTE_LOWAT) |
|
return (kn->kn_data >= kn->kn_sdata); |
|
return (kn->kn_data >= so->so_rcv.sb_lowat); |
|
} |
|
|
|
static void |
|
filt_sowdetach(struct knote *kn) |
|
{ |
|
struct socket *so; |
|
|
|
so = (struct socket *)kn->kn_fp->f_data; |
|
SLIST_REMOVE(&so->so_snd.sb_sel.sel_klist, kn, knote, kn_selnext); |
|
if (SLIST_EMPTY(&so->so_snd.sb_sel.sel_klist)) |
|
so->so_snd.sb_flags &= ~SB_KNOTE; |
|
} |
|
|
|
/*ARGSUSED*/ |
|
static int |
|
filt_sowrite(struct knote *kn, long hint) |
|
{ |
|
struct socket *so; |
|
|
|
so = (struct socket *)kn->kn_fp->f_data; |
|
kn->kn_data = sbspace(&so->so_snd); |
|
if (so->so_state & SS_CANTSENDMORE) { |
|
kn->kn_flags |= EV_EOF; |
|
kn->kn_fflags = so->so_error; |
|
return (1); |
|
} |
|
if (so->so_error) /* temporary udp error */ |
|
return (1); |
|
if (((so->so_state & SS_ISCONNECTED) == 0) && |
|
(so->so_proto->pr_flags & PR_CONNREQUIRED)) |
|
return (0); |
|
if (kn->kn_sfflags & NOTE_LOWAT) |
|
return (kn->kn_data >= kn->kn_sdata); |
|
return (kn->kn_data >= so->so_snd.sb_lowat); |
|
} |
|
|
|
/*ARGSUSED*/ |
|
static int |
|
filt_solisten(struct knote *kn, long hint) |
|
{ |
|
struct socket *so; |
|
|
|
so = (struct socket *)kn->kn_fp->f_data; |
|
|
|
/* |
|
* Set kn_data to number of incoming connections, not |
|
* counting partial (incomplete) connections. |
|
*/ |
|
kn->kn_data = so->so_qlen; |
|
return (kn->kn_data > 0); |
|
} |
|
|
|
static const struct filterops solisten_filtops = |
|
{ 1, NULL, filt_sordetach, filt_solisten }; |
|
static const struct filterops soread_filtops = |
|
{ 1, NULL, filt_sordetach, filt_soread }; |
|
static const struct filterops sowrite_filtops = |
|
{ 1, NULL, filt_sowdetach, filt_sowrite }; |
|
|
|
int |
|
soo_kqfilter(struct file *fp, struct knote *kn) |
|
{ |
|
struct socket *so; |
|
struct sockbuf *sb; |
|
|
|
so = (struct socket *)kn->kn_fp->f_data; |
|
switch (kn->kn_filter) { |
|
case EVFILT_READ: |
|
if (so->so_options & SO_ACCEPTCONN) |
|
kn->kn_fop = &solisten_filtops; |
|
else |
|
kn->kn_fop = &soread_filtops; |
|
sb = &so->so_rcv; |
|
break; |
|
case EVFILT_WRITE: |
|
kn->kn_fop = &sowrite_filtops; |
|
sb = &so->so_snd; |
|
break; |
|
default: |
|
return (1); |
|
} |
|
SLIST_INSERT_HEAD(&sb->sb_sel.sel_klist, kn, kn_selnext); |
|
sb->sb_flags |= SB_KNOTE; |
|
return (0); |
|
} |
|
|