Home Contents | # rawio.socketpair | Rawio | Core4 Lua Event System

## SYNOPSIS

handle1, handle2 = rawio.socketpair()

## DESCRIPTION

Creates a socketpair, which is an object allowing bidirectional data flow, and allocates a pair of file descriptors. Data written to one of the handles can be read from the other handle, and vice versa. This can be used to pass data between separate processes, see event:spawn() or os.spawn(). The socketpair itself persists until all its associated descriptors are closed.

A socketpair where only one handle has been closed is considered widowed. Writing on the remaining handle causes the write to return a broken pipe error. On the other hand, reading from the remaining handle will first return any buffered data, if any, and then return a zero count.

It is possible to shut down one or both directions of a socketpair by calling rawio:shutdown().

When shutting down one end of a socket pair for writing, then writing to that end is no longer allowed. Reading from the other end will return all buffered data, then signal an end of file. Shutting down one end of a socket pair for reading is the same as shutting down the other end for writing. All shutdowns are final.

A similar object which supports passing data in one direction only is a pipe.

## RETURN VALUE

On success, returns two rawio handles. On error, three values are returned: nil, a string describing the error (The result of the C library call strerror() on the errno code) and the errno number from the standard C library.

## SEE ALSO

event:spawn(), os.spawn(), rawio.pipe(), rawio:shutdown()