0

Basically, I'm wondering whether I can mix this with this.

Use case is that I'm designing a multi-process server in which the worker processes must be able to send file descriptors to another, specific (depends on the fd) worker process, and I don't want to keep O(n^2) unix domain sockets open to have them all connected to each other.

The alternative, of course, would be to have them open a connection as needed, send one message, then close the connection, every time they need to send an fd.

The platforms I care about are Linux, OSX, HP-UX, AIX, and Solaris.

Bwmat
  • 4,314
  • 3
  • 27
  • 42
  • You should be able to; but you need to be aware that datagrams are not guaranteed delivery so you stand the chance of losing the packet. – AlienHoboken May 05 '15 at 22:53
  • My understanding is that unix domain sockets were guaranteed delivery, regardless of type. Do you have a link to documentation saying otherwise? – Bwmat May 05 '15 at 23:39
  • You're right @Bwmat I forgot about that. I suppose the only difference then is that the DGRAM might be easier to manage in your case. – AlienHoboken May 05 '15 at 23:44

1 Answers1

0

Can unix domain sockets be used to send file descriptors between processes when used in connectionless mode?

Yes. From man page:

UNIX domain sockets support passing file descriptors or process credentials to other processes using ancillary data.

Reliability is not a concern. Datagram sockets are always reliable. Again from man page:

UNIX domain datagram sockets are always reliable and don't reorder datagrams

And with Unix domain sockets the only tangible (or that one should consider) difference b/w stream and datagram socket is one being connection oriented and one connection less. "Stream" and "Bound messages" are not of concern.

Man page also mentions about SEQPACKET socket type that allows preserving message boundaries in a connection oriented setup.

So, one could keep things simple and use datagram sockets.

Prabhu
  • 3,443
  • 15
  • 26