netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add MSG_WAITFORONE flag to recvmmsg
@ 2010-03-26 22:35 Brandon L Black
  2010-03-26 22:44 ` Eric Dumazet
  0 siblings, 1 reply; 10+ messages in thread
From: Brandon L Black @ 2010-03-26 22:35 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Arnaldo Carvalho de Melo, Ulrich Drepper,
	linux-kernel


From: Brandon L Black <blblack@gmail.com>

Add new flag MSG_WAITFORONE for the recvmmsg() syscall.
When this flag is specified for a blocking socket, recvmmsg()
will only block until at least 1 packet is available.  The
default behavior is to block until all vlen packets are
available.  This flag has no effect on non-blocking sockets
or when used in combination with MSG_DONTWAIT.

Signed-off-by: Brandon L Black <blblack@gmail.com>

---
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 7b3aae2..354cc56 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -255,6 +255,7 @@ struct ucred {
 #define MSG_ERRQUEUE	0x2000	/* Fetch message from error queue */
 #define MSG_NOSIGNAL	0x4000	/* Do not generate SIGPIPE */
 #define MSG_MORE	0x8000	/* Sender will send more */
+#define MSG_WAITFORONE	0x10000	/* recvmmsg(): block until 1+ packets avail */
 
 #define MSG_EOF         MSG_FIN
 
diff --git a/net/socket.c b/net/socket.c
index 769c386..33304d1 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2133,7 +2133,10 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
 
 		if (err)
 			break;
-		++datagrams;
+
+		/* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */
+		if (!datagrams++ && (flags & MSG_WAITFORONE))
+			flags |= MSG_DONTWAIT;
 
 		if (timeout) {
 			ktime_get_ts(timeout);

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-03-27 15:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-26 22:35 [PATCH] Add MSG_WAITFORONE flag to recvmmsg Brandon L Black
2010-03-26 22:44 ` Eric Dumazet
2010-03-26 22:55   ` Brandon Black
2010-03-27  2:07     ` Ulrich Drepper
2010-03-27  2:18       ` [PATCH v2] " Brandon L Black
2010-03-27  3:54         ` David Miller
2010-03-27 14:07           ` Arnaldo Carvalho de Melo
2010-03-27 15:29             ` David Miller
2010-03-27  4:58         ` Ulrich Drepper
2010-03-27  6:00         ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).