guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: socketpairs


From: Alex Vong
Subject: Re: socketpairs
Date: Fri, 08 Feb 2019 23:20:27 +0800
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Hello,

Catonano <address@hidden> writes:

> I don't understand what socketpairs are for
>
> The manual states:
>
>  -- Scheme Procedure: socketpair family style proto
>  -- C Function: scm_socketpair (family, style, proto)
>      Return a pair, the ‘car’ and ‘cdr’ of which are two unnamed socket
>      ports connected to each other.  The connection is full-duplex, so
>      data can be transferred in either direction between the two.
>
>
> and what's the point of having 2 ports connected to each other ?
>
> what's the use case meant to be covered by this ?
> What's the scenario ?
>
Usually, to answer this kind of questions, you can read the man page for
the original syscall. So running 'man socketpair(2)' should give you
more details.

In this case, Mike has already given an overview. I'll also try to give
another explanation:

A socketpair is similar to a pipe. When you call pipe(2), the syscall
returns both the reading and writing end of the pipe. Then you fork(2)
and exec(3). Next, you can close the reading end on the parent process
and close the writing end of child process. This way the parent process
can "pipe" data to the child process.

Of course, the opposite works as well: you can choose to close the
writing end on the parent process and close the reading end of child
process. Then the child process can "pipe" data to the parent process.

The point is that this is uni-directional only: data can only go in one
direction. What if you want a bi-directional pipe? Well, this is the
case that you want a socketpair[0].

>
>      FAMILY, STYLE and PROTO are as per ‘socket’ above.  But many
>      systems only support socket pairs in the ‘PF_UNIX’ family.  Zero is
>      likely to be the only meaningful value for PROTO.
>
> Ah so many systems only support socket pairs in the PF_UNIX family
>
> So the use case is supposedly meant to be on a single machine, not through
> the network
>
> Again, what are we talking about here ?
>
As I've mentioned above, a socketpair can be used as a bi-directional
pipe a single machine. You can read more about the socket system by
running 'man socket(2)', 'man socket(7)' and 'man unix(7)'. Especially
those man pages in section 7, they usually give a good overview.

> Thanks

Cheers,
Alex

[0]: 
https://stackoverflow.com/questions/1583005/is-there-any-difference-between-socketpair-and-pair-of-unnamed-pipes

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]