diff options
| -rw-r--r-- | lib/libc/sys/kqueue.2 | 2 | ||||
| -rw-r--r-- | sys/kern/uipc_socket.c | 2 | ||||
| -rw-r--r-- | sys/sys/socketvar.h | 5 |
3 files changed, 7 insertions, 2 deletions
diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index e7cde201d82c..0dae6b157cfb 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -226,7 +226,7 @@ and specifying the new low water mark in .Va data . On return, .Va data -contains the number of bytes in the socket buffer. +contains the number of bytes of protocol data available to read. .Pp If the read direction of the socket has shutdown, then the filter also sets EV_EOF in diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index e07e58191132..7a6c2b57fcdd 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1784,7 +1784,7 @@ filt_soread(struct knote *kn, long hint) { struct socket *so = (struct socket *)kn->kn_fp->f_data; - kn->kn_data = so->so_rcv.sb_cc; + kn->kn_data = so->so_rcv.sb_cc - so->so_rcv.sb_ctl; if (so->so_state & SS_CANTRCVMORE) { kn->kn_flags |= EV_EOF; kn->kn_fflags = so->so_error; diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index 15a7a0073737..4c94157a65d3 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -105,6 +105,7 @@ struct socket { u_int sb_hiwat; /* max actual char count */ u_int sb_mbcnt; /* chars of mbufs used */ u_int sb_mbmax; /* max chars of mbufs to use */ + u_int sb_ctl; /* non-data chars in buffer */ int sb_lowat; /* low water mark */ int sb_timeo; /* timeout for read/write */ short sb_flags; /* flags, see below */ @@ -227,6 +228,8 @@ struct xsocket { /* adjust counters in sb reflecting allocation of m */ #define sballoc(sb, m) { \ (sb)->sb_cc += (m)->m_len; \ + if ((m)->m_type != MT_DATA) \ + (sb)->sb_ctl += (m)->m_len; \ (sb)->sb_mbcnt += MSIZE; \ if ((m)->m_flags & M_EXT) \ (sb)->sb_mbcnt += (m)->m_ext.ext_size; \ @@ -235,6 +238,8 @@ struct xsocket { /* adjust counters in sb reflecting freeing of m */ #define sbfree(sb, m) { \ (sb)->sb_cc -= (m)->m_len; \ + if ((m)->m_type != MT_DATA) \ + (sb)->sb_ctl -= (m)->m_len; \ (sb)->sb_mbcnt -= MSIZE; \ if ((m)->m_flags & M_EXT) \ (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \ |
