Re: Want something like a pipe with multiple readers and/or multiple writers

From: Andrei Voropaev (avorop_at_mail.ru)
Date: 04/29/04


Date: 29 Apr 2004 09:03:52 GMT

On 2004-04-28, Brady Montz <bradym@balestra.org> wrote:
> I've got a distributed app where there's a master process, and a bunch
> of slaves. All running on the same machine. The master process
> periodically needs to messages to the slaves, and they periodically
> need to send messages back.
>
> The master doesn't need to know how many slaves there are, or to
> distinguish between them.
>
> Ideally, what I would like is something like a pipe or socket where
> when the master writes a message to it, all the slaves get a copy on
> their end. And, similarly, a single file descriptor the master can
> read from, with a well known address, where any slave could write to
> it and have the master see the message.
>
> Finally, this needs to be portable across various unixes.
>
> I kinda doubt that the basic pipes or sockets can do this, but I might
> as well ask: can they? And if not, then is there some library or
> toolkit somewhere that provides this?

Probably you can look into udp socket with multicasting. In similar
situation I've used slightly different approach. Unix DGRAM sockets.
Master has one socket. Each slave registers itself with master by
sending datagram to the master's socket. Then master sends messages to
appropriate slaves. For me this works better because regulary I need to
send datagrams from master to specific slaves, not to all of them. If
you really don't want to track the addresses of all slaves, then you
shall use multicasting. Then each slave simply tells kernel that he
should get copy of datagrams with specific address. So kernel will keep
trace of the addresses of your slaves :)

Andrei



Relevant Pages