Skip to contentSkip to conversation

Add MSG_WAITFORONE flag to recvmmsg

PATCH Superseded Brandon L Black 5 participants 10 messages Mar 26, 2010 – Mar 27, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add MSG_WAITFORONE flag to recvmmsg

From: Brandon L Black <[email protected]>

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.

---

include/linux/socket.h +1 -0
index 7b3aae2..354cc56 100644
@@ -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
 
net/socket.c +4 -1
index 769c386..33304d1 100644
@@ -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);
#1 lore raw
Quoted 31 lines · Brandon L Black

From: Brandon L Black <[email protected]>

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.

---

include/linux/socket.h +1 -0
index 7b3aae2..354cc56 100644
@@ -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
 
net/socket.c +0 -0
index 769c386..33304d1 100644

net/socket.c int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen, · line 2139

Quoted 8 lines
net/socket.c +4 -1
@@ -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;
#2 lore raw
Quoted 7 lines · Eric Dumazet

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

#3 lore raw
Quoted 2 lines · Brandon Black

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.

#4 lore raw

PATCH v2 1/1 Add MSG_WAITFORONE flag to recvmmsg

From: Brandon L Black <[email protected]>

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.

---

include/linux/socket.h +1 -0
index 7b3aae2..354cc56 100644
@@ -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
 
net/socket.c +4 -0
index 769c386..f55ffe9 100644
@@ -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);
maintainer
#5 lore raw

From: Brandon L Black <[email protected]>
Date: Fri, 26 Mar 2010 21:18:03 -0500

Quoted 11 lines

From: Brandon L Black <[email protected]>

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.

Arnaldo, please review this, thanks.

#6 lore raw

Em Fri, Mar 26, 2010 at 08:54:28PM -0700, David Miller escreveu:

Quoted 13 lines

From: Brandon L Black <[email protected]>
Date: Fri, 26 Mar 2010 21:18:03 -0500

Quoted 10 lines

From: Brandon L Black <[email protected]>

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.

Quoted 3 lines
Quoted 1 line

Arnaldo, please review this, thanks.

I'm ok with it.

- Arnaldo

maintainer Applied
#7 lore raw

From: Arnaldo Carvalho de Melo <[email protected]>
Date: Sat, 27 Mar 2010 11:07:17 -0300

Quoted 14 lines

Em Fri, Mar 26, 2010 at 08:54:28PM -0700, David Miller escreveu:

Quoted 13 lines

From: Brandon L Black <[email protected]>
Date: Fri, 26 Mar 2010 21:18:03 -0500

Quoted 10 lines

From: Brandon L Black <[email protected]>

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.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Arnaldo, please review this, thanks.

I'm ok with it.

Applied, thanks everyone.

Acked-by on v2 1/1
#8 lore raw
In reply to Brandon L Black
Quoted 8 lines · Brandon L Black

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.

This is useful and looks OK to me.

Acked-by on v2 1/1
#9 lore raw
In reply to Brandon L Black
Quoted 11 lines · Brandon L Black

From: Brandon L Black <[email protected]>

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.

Quoted 29 lines

---

include/linux/socket.h +1 -0
index 7b3aae2..354cc56 100644
@@ -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
 
net/socket.c +4 -1
index 769c386..f55ffe9 100644
@@ -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);
--