[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fork() and socketpair()
Francesco Orsenigo wrote:
>
> My program forks into two separate processes, and i must connect them with a
> pipe wich i must be able to use with send() and recv().
> socketpair is perfect (i socketpair() and then fork()) but it seems not very
> portable.
> The alternative would be fork() and then link the two processes with standard
> socket()/connect()/listen() calls.
>
> I thought about using pipe(), but it is not full-duplex and i don't know if
> it is safe to use with send() and recv().
Well, you can use TWO calls to 'pipe()' (one for each direction) and use
read/write instead of send/recv().
Pipes and sockets are entirely different mechanisms - pipes use file-system
calls (hence read/write) and sockets use network-system calls (hence send/recv).
socketpair is somewhat portable because it conforms to the BSD4.4 spec.
The man page says:
CONFORMING TO
4.4BSD (the socketpair function call appeared in 4.2BSD).
Generally portable to/from non-BSD systems supporting
clones of the BSD socket layer (including System V vari
ants).
You might also consider "named pipes" (aka FIFO's) which can be opened
just like files.
----------------------------- Steve Baker -------------------------------
Mail : <sjbaker1@airmail.net> WorkMail: <sjbaker@link.com>
URLs : http://www.sjbaker.org
http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net
http://prettypoly.sf.net http://freeglut.sf.net
http://toobular.sf.net http://lodestone.sf.net