cmsg.3: Add a scatter/gather buffer to sample code
PATCH 1/1 cmsg.3: Add a scatter/gather buffer to sample code
Quoted 2 lines
From
b2800c8d5dcd8ede89ebccb25f1a9b087dc2684bMon Sep 17 00:00:00 2001
From: Sukadev Bhattiprolu <[email protected]>
Date: Wed, 19 Jul 2017 22:47:14 -0400
Subject: [PATCH 1/1] cmsg.3: Add a scatter/gather buffer to sample code
Add a simple scatter/gather buffer to the cmsg sample code.
It appears that the scatter/gather buffer is required even though it may not be used. In my testing (on Fedora 24 4.8.7-200.fc24.x86_64 as well as a 4.11 based kernel) return value of sendmsg() was the number of bytes in the scatter/gather buffer (1 with the patch below).
Without the iovec buffer, sendmsg() returns 0 which means no bytes were transferred and the corresponding recvmsg() blocks indefinitely.
---
A sample test case is at:
https://github.com/sukadev/linux-tests/blob/master/share-fds/share-fds.c
man3/cmsg.3 | 7 +++++++ 1 file changed, 7 insertions(+)
man3/cmsg.3 +7 -0
@@ -200,12 +200,19 @@ struct msghdr msg = { 0 }; struct cmsghdr *cmsg; int myfds[NUM_FD]; /* Contains the file descriptors to pass */ int *fdptr; +char iobuf[1]; +struct iovec io = { + .iov_base = iobuf, + .iov_len = sizeof(iobuf) +}; union { /* Ancillary data buffer, wrapped in a union in order to ensure it is suitably aligned */ char buf[CMSG_SPACE(sizeof(myfds))]; struct cmsghdr align; } u; +msg.msg_iov = &io; +msg.msg_iovlen = 1; msg.msg_control = u.buf; msg.msg_controllen = sizeof(u.buf); cmsg = CMSG_FIRSTHDR(&msg);
Signature · 6 lines
1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20170719234955.GA24570-r/[email protected]
Quoted 8 lines · Sukadev Bhattiprolu
Quoted 2 lines
From
b2800c8d5dcd8ede89ebccb25f1a9b087dc2684bMon Sep 17 00:00:00 2001From: Sukadev Bhattiprolu <[email protected]>
Date: Wed, 19 Jul 2017 22:47:14 -0400
Subject: [PATCH 1/1] cmsg.3: Add a scatter/gather buffer to sample codeAdd a simple scatter/gather buffer to the cmsg sample code.
Quoted 7 lines
It appears that the scatter/gather buffer is required even though it may not be used. In my testing (on Fedora 24 4.8.7-200.fc24.x86_64 as well as a 4.11 based kernel) return value of
sendmsg()was the number of bytes in the scatter/gather buffer (1 with the patch below).Without the iovec buffer,
sendmsg()returns 0 which means no bytes were transferred and the correspondingrecvmsg()blocks indefinitely.
Thanks, Sukadev. Applied.
Cheers,
Michael
Quoted 35 lines
Signed-off-by Sukadev Bhattiprolu <[email protected]>---
A sample test case is at:
https://github.com/sukadev/linux-tests/blob/master/share-fds/share-fds.cman3/cmsg.3 | 7 +++++++ 1 file changed, 7 insertions(+)man3/cmsg.3 +7
-0@@ -200,12 +200,19 @@ struct msghdr msg = { 0 }; struct cmsghdr *cmsg; int myfds[NUM_FD]; /* Contains the file descriptors to pass */ int *fdptr; +char iobuf[1]; +struct iovec io = { + .iov_base = iobuf, + .iov_len = sizeof(iobuf) +}; union { /* Ancillary data buffer, wrapped in a union in order to ensure it is suitably aligned */ char buf[CMSG_SPACE(sizeof(myfds))]; struct cmsghdr align; } u; +msg.msg_iov = &io; +msg.msg_iovlen = 1; msg.msg_control = u.buf; msg.msg_controllen = sizeof(u.buf); cmsg = CMSG_FIRSTHDR(&msg);
Signature · 7 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html