From 5af0f223d1d6f8588b3c14d7d95a625060b4c95f Mon Sep 17 00:00:00 2001 From: Michael Kerrisk Date: Tue, 17 Jul 2018 09:39:56 +0200 Subject: [PATCH] unix.7: Ancillary data forms a barrier when receiving on a stream socket Thanks to a tip from Keith Packard: https://keithp.com/blogs/fd-passing/ (Also verified by experiment.) Signed-off-by: Michael Kerrisk --- man7/unix.7 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/man7/unix.7 b/man7/unix.7 index 905d5bc2f..38e00c6c8 100644 --- a/man7/unix.7 +++ b/man7/unix.7 @@ -455,6 +455,33 @@ it is not necessary on Linux to send any accompanying real data. However, portable applications should also include at least one byte of real data when sending ancillary data over a datagram socket. .PP +When receiving from a stream socket, +ancillary data forms a kind of barrier for the received data. +For example, suppose that the sender transmits as follows: +.PP +.RS +.PD 0 +.IP 1. 3 +.BR sendmsg (2) +of four bytes, with no ancillary data. +.IP 2. +.BR sendmsg (2) +of one byte, with ancillary data. +.IP 3. +.BR sendmsg (2) +of four bytes, with no ancillary data. +.PD +.RE +.PP +Suppose that the receiver now performs +.BR recvmsg (2) +calls each with a buffer size of 20 bytes. +The first call will receive five bytes of data, +along with the ancillary data sent by the second +.BR sendmsg (2) +call. +The next call will receive the remaining five bytes of data. +.PP If the space allocated for receiving incoming ancillary data is too small then the ancillary data is truncated to the number of headers that will fit in the supplied buffer (or, in the case of an