Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] Add MSG_WAITFORONE flag to recvmmsg

23 views
Skip to first unread message

Brandon L Black

unread,
Mar 26, 2010, 6:40:02 PM3/26/10
to

From: Brandon L Black <blb...@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 <blb...@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);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Eric Dumazet

unread,
Mar 26, 2010, 6:50:02 PM3/26/10
to


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

++datagrams;

if (flags & MSG_WAITFORONE)
flags |= MSG_DONTWAIT;

Brandon Black

unread,
Mar 26, 2010, 7:00:01 PM3/26/10
to
On Fri, Mar 26, 2010 at 5:44 PM, Eric Dumazet <eric.d...@gmail.com> 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

Ulrich Drepper

unread,
Mar 26, 2010, 10:10:01 PM3/26/10
to
On Fri, Mar 26, 2010 at 15:55, Brandon Black <blb...@gmail.com> 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.

Brandon L Black

unread,
Mar 26, 2010, 10:20:02 PM3/26/10
to

From: Brandon L Black <blb...@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 <blb...@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..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);

David Miller

unread,
Mar 27, 2010, 12:00:02 AM3/27/10
to
From: Brandon L Black <blb...@gmail.com>
Date: Fri, 26 Mar 2010 21:18:03 -0500

>
> From: Brandon L Black <blb...@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 <blb...@gmail.com>

Arnaldo, please review this, thanks.

Ulrich Drepper

unread,
Mar 27, 2010, 1:00:02 AM3/27/10
to
On Fri, Mar 26, 2010 at 19:18, Brandon L Black <blb...@gmail.com> 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 <blb...@gmail.com>

This is useful and looks OK to me.

Acked-by: Ulrich Drepper <dre...@redhat.com>

Eric Dumazet

unread,
Mar 27, 2010, 2:10:01 AM3/27/10
to
Le vendredi 26 mars 2010 à 21:18 -0500, Brandon L Black a écrit :
> From: Brandon L Black <blb...@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 <blb...@gmail.com>
>

Acked-by: Eric Dumazet <eric.d...@gmail.com>

Arnaldo Carvalho de Melo

unread,
Mar 27, 2010, 10:10:02 AM3/27/10
to
Em Fri, Mar 26, 2010 at 08:54:28PM -0700, David Miller escreveu:
> From: Brandon L Black <blb...@gmail.com>
> Date: Fri, 26 Mar 2010 21:18:03 -0500
>
> >
> > From: Brandon L Black <blb...@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 <blb...@gmail.com>
>
> Arnaldo, please review this, thanks.

I'm ok with it.

Acked-by: Arnaldo Carvalho de Melo <ac...@redhat.com>

- Arnaldo

David Miller

unread,
Mar 27, 2010, 11:30:01 AM3/27/10
to
From: Arnaldo Carvalho de Melo <ac...@redhat.com>
Date: Sat, 27 Mar 2010 11:07:17 -0300

> Em Fri, Mar 26, 2010 at 08:54:28PM -0700, David Miller escreveu:
>> From: Brandon L Black <blb...@gmail.com>
>> Date: Fri, 26 Mar 2010 21:18:03 -0500
>>
>> >
>> > From: Brandon L Black <blb...@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 <blb...@gmail.com>
>>
>> Arnaldo, please review this, thanks.
>
> I'm ok with it.
>
> Acked-by: Arnaldo Carvalho de Melo <ac...@redhat.com>

Applied, thanks everyone.

0 new messages