[PATCH] Add MSG_WAITFORONE flag to recvmmsg

Subsystems: networking [general], networking [sockets], the rest

STALE6014d

10 messages, 5 authors, 2010-03-27 · open the first message on its own page

[PATCH] Add MSG_WAITFORONE flag to recvmmsg

From: Brandon L Black <hidden>
Date: 2010-03-26 22:35:40

From: Brandon L Black <redacted>

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

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

Re: [PATCH] Add MSG_WAITFORONE flag to recvmmsg

From: Eric Dumazet <hidden>
Date: 2010-03-26 22:44:38

Le vendredi 26 mars 2010 à 17:35 -0500, Brandon L Black a écrit :
From: Brandon L Black <redacted>

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 <redacted>
quoted hunk
---
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;

Hmmm, no need to test !datagram, just do :

	++datagrams;

	if (flags & MSG_WAITFORONE)
		flags |= MSG_DONTWAIT;


Re: [PATCH] Add MSG_WAITFORONE flag to recvmmsg

From: Brandon Black <hidden>
Date: 2010-03-26 22:55:21

On Fri, Mar 26, 2010 at 5:44 PM, Eric Dumazet [off-list ref] wrote:
Hmmm, no need to test !datagram, just do :

       ++datagrams;

       if (flags & MSG_WAITFORONE)
               flags |= MSG_DONTWAIT;
Ok.  I've never been through this process before.  Do I resubmit a new
subject/thread with the changed patch and [PATCH v2] at this point?
Any other nits about how the patch was sent before I do?

Thanks,
-- Brandon

Re: [PATCH] Add MSG_WAITFORONE flag to recvmmsg

From: Ulrich Drepper <hidden>
Date: 2010-03-27 02:07:33

On Fri, Mar 26, 2010 at 15:55, Brandon Black [off-list ref] wrote:
Ok.  I've never been through this process before.  Do I resubmit a new
subject/thread with the changed patch and [PATCH v2] at this point?
The patch is small enough for this to be OK.

[PATCH v2] Add MSG_WAITFORONE flag to recvmmsg

From: Brandon L Black <hidden>
Date: 2010-03-27 02:18:07

From: Brandon L Black <redacted>

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

---
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..f55ffe9 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2135,6 +2135,10 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
 			break;
 		++datagrams;
 
+		/* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */
+		if (flags & MSG_WAITFORONE)
+			flags |= MSG_DONTWAIT;
+
 		if (timeout) {
 			ktime_get_ts(timeout);
 			*timeout = timespec_sub(end_time, *timeout);

Re: [PATCH v2] Add MSG_WAITFORONE flag to recvmmsg

From: David Miller <davem@davemloft.net>
Date: 2010-03-27 03:54:09

From: Brandon L Black <redacted>
Date: Fri, 26 Mar 2010 21:18:03 -0500
From: Brandon L Black <redacted>

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 <redacted>
Arnaldo, please review this, thanks.

Re: [PATCH v2] Add MSG_WAITFORONE flag to recvmmsg

From: Ulrich Drepper <hidden>
Date: 2010-03-27 04:58:46

On Fri, Mar 26, 2010 at 19:18, Brandon L Black [off-list ref] wrote:
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 <redacted>
This is useful and looks OK to me.

Acked-by: Ulrich Drepper <redacted>

Re: [PATCH v2] Add MSG_WAITFORONE flag to recvmmsg

From: Eric Dumazet <hidden>
Date: 2010-03-27 06:00:12

Le vendredi 26 mars 2010 à 21:18 -0500, Brandon L Black a écrit :
From: Brandon L Black <redacted>

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 <redacted>
Acked-by: Eric Dumazet <redacted>
quoted hunk
---
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..f55ffe9 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2135,6 +2135,10 @@ int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
 			break;
 		++datagrams;
 
+		/* MSG_WAITFORONE turns on MSG_DONTWAIT after one packet */
+		if (flags & MSG_WAITFORONE)
+			flags |= MSG_DONTWAIT;
+
 		if (timeout) {
 			ktime_get_ts(timeout);
 			*timeout = timespec_sub(end_time, *timeout);
--

Re: [PATCH v2] Add MSG_WAITFORONE flag to recvmmsg

From: Arnaldo Carvalho de Melo <hidden>
Date: 2010-03-27 14:07:25

Em Fri, Mar 26, 2010 at 08:54:28PM -0700, David Miller escreveu:
From: Brandon L Black <redacted>
Date: Fri, 26 Mar 2010 21:18:03 -0500
quoted
From: Brandon L Black <redacted>

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 <redacted>
Arnaldo, please review this, thanks.
I'm ok with it.

Acked-by: Arnaldo Carvalho de Melo <redacted>

- Arnaldo

Re: [PATCH v2] Add MSG_WAITFORONE flag to recvmmsg

From: David Miller <davem@davemloft.net>
Date: 2010-03-27 15:28:48

From: Arnaldo Carvalho de Melo <redacted>
Date: Sat, 27 Mar 2010 11:07:17 -0300
Em Fri, Mar 26, 2010 at 08:54:28PM -0700, David Miller escreveu:
quoted
From: Brandon L Black <redacted>
Date: Fri, 26 Mar 2010 21:18:03 -0500
quoted
From: Brandon L Black <redacted>

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 <redacted>
Arnaldo, please review this, thanks.
I'm ok with it.

Acked-by: Arnaldo Carvalho de Melo <redacted>
Applied, thanks everyone.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help