Track the number of non-data chararacters stored in socket buffers so that

the data value returned by kevent()'s EVFILT_READ filter on non-TCP
sockets accurately reflects the amount of data that can be read from the
sockets by applications.

PR:		30634
Reviewed by:	-net, -arch
Sponsored by:	NTT Multimedia Communications Labs
MFC after:	2 weeks
This commit is contained in:
Kelly Yancey 2002-11-01 21:27:59 +00:00
parent 6cedb451fb
commit e0f640e82d
3 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -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; \