svn commit: r260824 - in projects/sendfile/sys: kern sys
Gleb Smirnoff
glebius at FreeBSD.org
Fri Jan 17 11:23:25 UTC 2014
Author: glebius
Date: Fri Jan 17 11:23:24 2014
New Revision: 260824
URL: http://svnweb.freebsd.org/changeset/base/260824
Log:
sbready() function tells that 'count' mbufs starting from the 'm'
in the buffer 'sb' are now ready.
Function returns 0 if 'm' was the first one, and now socket has data
to send, otherwise EWOULDBLOCK.
Sponsored by: Netflix
Sponsored by: Nginx, Inc.
Modified:
projects/sendfile/sys/kern/uipc_sockbuf.c
projects/sendfile/sys/sys/sockbuf.h
Modified: projects/sendfile/sys/kern/uipc_sockbuf.c
==============================================================================
--- projects/sendfile/sys/kern/uipc_sockbuf.c Fri Jan 17 11:20:23 2014 (r260823)
+++ projects/sendfile/sys/kern/uipc_sockbuf.c Fri Jan 17 11:23:24 2014 (r260824)
@@ -84,6 +84,44 @@ sb_shift_nrdy(struct sockbuf *sb, struct
sb->sb_fnrdy = m;
}
+int
+sbready(struct sockbuf *sb, struct mbuf *m, int count)
+{
+ u_int blocker;
+
+ SOCKBUF_LOCK(sb);
+
+ KASSERT(sb->sb_fnrdy != NULL, ("%s: sb %p NULL fnrdy", __func__, sb));
+
+ blocker = (sb->sb_fnrdy == m) ? M_BLOCKED : 0;
+
+ for (int i = 0; i < count; i++, m = m->m_next) {
+ KASSERT(m->m_flags & M_NOTREADY,
+ ("%s: m %p !M_NOTREADY", __func__, m));
+ m->m_flags &= ~(M_NOTREADY | blocker);
+ sb->sb_acc += m->m_len;
+ }
+
+ if (!blocker) {
+ SOCKBUF_UNLOCK(sb);
+ return (EWOULDBLOCK);
+ }
+
+ /* This one was blocking all the queue. */
+ for (; m && (m->m_flags & M_NOTREADY) == 0; m = m->m_next) {
+ KASSERT(m->m_flags & M_BLOCKED,
+ ("%s: m %p !M_BLOCKED", __func__, m));
+ m->m_flags &= ~M_BLOCKED;
+ sb->sb_acc += m->m_len;
+ }
+
+ sb->sb_fnrdy = m;
+
+ SOCKBUF_UNLOCK(sb);
+
+ return (0);
+}
+
/*
* Adjust sockbuf state reflecting allocation of m.
*/
Modified: projects/sendfile/sys/sys/sockbuf.h
==============================================================================
--- projects/sendfile/sys/sys/sockbuf.h Fri Jan 17 11:20:23 2014 (r260823)
+++ projects/sendfile/sys/sys/sockbuf.h Fri Jan 17 11:23:24 2014 (r260824)
@@ -173,6 +173,7 @@ void sbunlock(struct sockbuf *sb);
void sballoc(struct sockbuf *, struct mbuf *);
void sbfree(struct sockbuf *, struct mbuf *);
void sbmtrim(struct sockbuf *, struct mbuf *, int);
+int sbready(struct sockbuf *, struct mbuf *, int);
static inline u_int
sbavail(struct sockbuf *sb)
More information about the svn-src-projects
mailing list