[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fork() and socketpair()
Francesco Orsenigo:
> Joerg Seebohn:
> > I do not know what portability consideration you have in mind,
> > but under Linux a call to socketpair is perfect:
> > int sv[2] ;
> > int r = socketpair( PF_UNIX, SOCK_STREAM, AF_LOCAL, sv) ;
>
> Yes, i called socketpair with the wrong arguments, now it works.
> I was using "socketpair(AF_INET, SOCK_STREAM, 0, sd)".
>
> Is possible to use PF_UNIX under other environments?
> (Thank you, you've got me out of a trouble!)
A call to socketpair should work also for internet protocols,
but you must use the TCP protocol for SOCK_STREAM sockets:
#include <netinet/in.h> // defines IPPROTO_TCP
int sv[2] ;
int r = socketpair( PF_INET, SOCK_STREAM, IPPROTO_TCP, sv) ;
The unix protocol family "PF_UNIX" works only under UNIX as the name
says and only for local communication but it is faster than "PF_INET" !
Joerg
Seebohn
http://www.s.netic.de/jseebohn