[ Team LiB ] |
15.3 socketpair FunctionThe socketpair function creates two sockets that are then connected together. This function applies only to Unix domain sockets.
The family must be AF_LOCAL and the protocol must be 0. The type, however, can be either SOCK_STREAM or SOCK_DGRAM. The two socket descriptors that are created are returned as sockfd[0] and sockfd[1].
The two created sockets are unnamed; that is, there is no implicit bind involved. The result of socketpair with a type of SOCK_STREAM is called a stream pipe. It is similar to a regular Unix pipe (created by the pipe function), but a stream pipe is full-duplex; that is, both descriptors can be read and written. We show a picture of a stream pipe created by socketpair in Figure 15.7.
|
[ Team LiB ] |