Skip to content

Commit f092276

Browse files
tomratbertdavem330
authored andcommitted
net: Add MSG_BATCH flag
Add a new msg flag called MSG_BATCH. This flag is used in sendmsg to indicate that more messages will follow (i.e. a batch of messages is being sent). This is similar to MSG_MORE except that the following messages are not merged into one packet, they are sent individually. sendmmsg is updated so that each contained message except for the last one is marked as MSG_BATCH. MSG_BATCH is a performance optimization in cases where a socket implementation can benefit by transmitting packets in a batch. Signed-off-by: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 28a94d8 commit f092276

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

include/linux/socket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ struct ucred {
274274
#define MSG_MORE 0x8000 /* Sender will send more */
275275
#define MSG_WAITFORONE 0x10000 /* recvmmsg(): block until 1+ packets avail */
276276
#define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */
277+
#define MSG_BATCH 0x40000 /* sendmmsg(): more messages coming */
277278
#define MSG_EOF MSG_FIN
278279

279280
#define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN */

net/socket.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,7 @@ int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
20082008
struct compat_mmsghdr __user *compat_entry;
20092009
struct msghdr msg_sys;
20102010
struct used_address used_address;
2011+
unsigned int oflags = flags;
20112012

20122013
if (vlen > UIO_MAXIOV)
20132014
vlen = UIO_MAXIOV;
@@ -2022,8 +2023,12 @@ int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
20222023
entry = mmsg;
20232024
compat_entry = (struct compat_mmsghdr __user *)mmsg;
20242025
err = 0;
2026+
flags |= MSG_BATCH;
20252027

20262028
while (datagrams < vlen) {
2029+
if (datagrams == vlen - 1)
2030+
flags = oflags;
2031+
20272032
if (MSG_CMSG_COMPAT & flags) {
20282033
err = ___sys_sendmsg(sock, (struct user_msghdr __user *)compat_entry,
20292034
&msg_sys, flags, &used_address, MSG_EOR);

0 commit comments

Comments
 (0)