Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNIX domain socket: is there such a thing as a "busy" signal?

Can a Client pushing data through a UNIX domain socket ( AF_UNIX type ) be signaled busy if the receiving end cannot cope with the load?

OR

Must there be a Client-Server protocol on top of the socket to handle flow control?

like image 567
jldupont Avatar asked Sep 25 '09 18:09

jldupont


1 Answers

You can definitely do a blocking send to a UNIX Domain socket. If the receiving side's receive buffer is full, or if the number of outstanding (undelivered) send socket buffers is too high, the sender will block.

SOCK_STREAM UNIX Domain Sockets work like TCP sockets. SOCK_DGRAM UNIX Domain Sockets work like UDP, except that UNIX Domain datagrams have guaranteed, in-order delivery, whereas UDP sockets can be re-ordered or dropped. (Also, UNIX Domain Sockets can be used to send file descriptors and pass user credentials between processes, neither of which can be done with TCP, UDP, or pipes.)

So, because in-order delivery is guaranteed by all types of UNIX Domain Sockets, the receiver can just stop receiving when it is busy doing other things, and the sender will be automatically blocked when there's no more buffer space available (or will be notified that there's no more buffer space, if they requested non-blocking operation on their socket). Then, when the receiver starts receiving again, the sender will be allowed to send more.

like image 54
jtchitty Avatar answered Oct 02 '22 21:10

jtchitty