Partial read / write problem in sendmsg / recvmsg

I am writing a program that transfers file descriptors between two processes, using sendmsgand recvmsgthrough a domain socket. To send the file descriptor, additional data is included in msghdr.msg_iovand msghdr.msg_iolen. However, I was informed that similar normal system calls readand write, sendmsgand recvmsgalso have a partial read / write problem. In this case, will the data in the auxiliary field for each partial information be automatically duplicated? I ask about this because my implementation requires a non-locking mechanism. Let me use the following example to describe it in more detail.

Sender: send msghdrdata containing fdin the auxiliary field and Kbytes tomsg_iov

Receiver: (1) partial read, K1bytes (2) partial read, K-K1bytes

Now, as the example above, I have to process the data after step (2) when all the data arrives. In this case, can I correctly extract fdfrom the auxiliary field? Or does he appear only in the first partial reading?

+4
source share
1 answer

gander (linux, . ), , , . , , EAGAIN/EWOULDBLOCK, , . - , ​​ . , .

, , ​​ , , ( - , ). , , , ​​ . ( , , , , ), - .

, , , - , .

, , .

, , stackexchange, @Klas-Lindbäck (https://unix.stackexchange.com/questions/185011/what-happens-with-unix-stream-ancillary-data-on-partial-reads). ( .)

Linux. , , , - . , , sendmsg msghdr, , msg_control .

+1

Source: https://habr.com/ru/post/1648220/


All Articles