AF_UNIX domain socket question.

Robert Thau rst at tardis.UUCP
Wed May 29 12:29:52 AEST 1985


>                                                         The reason
> being that I need to server to go into a read wait on a socket
> for data that could come from several processes at different times.
> I'd like to give each process its own socket in the usual way, but
> that means I'd have to go into an accept wait, and I want to be
> able to respond to data sent by earlier processes more or less immediately.

If a server socket is select(2)ed for read, the select will return with
"data available" on the server when a peer tries to connect.  You can then
accept() without the wait, since you already know someone's connecting.
Since there's probably a select() in your main loop anyway, this is the
way to go.  The 'pwrite' multi-way talk program which was posted to
net.sources a while ago worked like this; you might want to take a look.
(No flames... there's nothing wrong with pwrite that a sed script won't fix).

BTW, AF_UNIX is a bit flaky; although ordinary stream sockets do work,
out-of-band data and datagrams may or may not make the system go away
(depending on the phase of the moon and the patches that have been applied
at your site).  Internet sockets have a few advantages besides; they make
your program work intermachine with less work, and they make cleanup
on abnormal exit easier (nothing to unlink).

Robert Thau
rst at tardis.ARPA



More information about the Comp.unix.wizards mailing list