Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNIX domain sockets, send timeout, zero copy

I am learning UNIX domain sockets and trying out some client server programs. I am using SOCK_DGRAM family of sockets.

My doubt is:

  1. Is using UNIX domain sockets copy buffer from userspace to kernel space buffers while sending and receiving?

So my call:

sendto(send_thread_socket, (void*)argData, sizeof(*argData), 0,
                                        (struct sockaddr *)&dpdkServer, sizeof(struct sockaddr_un))

will it copy the buffer to some kernel space buffer or will it directly be copied to user space buffer of receiving process. Since UNIX sockets work on file system namespaces I thought it shouldn't do a copy of the buffer.

  1. Since I am using SOCK_DGRAM, will a send timeout make any sense?

Lets say I am using the same sendto() call, but the receiving side does not guarantee any timely collection of data, can I have a Send timeout.

like image 542
RootPhoenix Avatar asked Dec 08 '25 00:12

RootPhoenix


1 Answers

The function sendto does not wait for the data to be received by the recipient before it returns. So yes, to achieve that, the data will be copied to a buffer owned by the kernel and then copied out again by the recieving process.

Why: If this wasn't the case, then it would be more-or-less impossible for two processes to exchange messages. If process P1 attempts to send a message to process P2, it would not succeed until P2 called read. If P2 is attempting to send a messate to P1 at the time, it cannot succeed until P1 calls read. But P1 is waiting in a blocking call to sendto. The processes will be deadlocked.

Buffering by the kernel is the solution to that problem.

like image 148
Ben Avatar answered Dec 10 '25 12:12

Ben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!