Home  Contents

rawio.pipe

Rawio Core4 Lua Event System

SYNOPSIS

readhandle, writehandle = rawio.pipe()

DESCRIPTION

Creates a pipe, which is an object allowing unidirectional data flow, and allocates a pair of file descriptors. The first descriptor connects to the read end of the pipe, and the second connects to the write end, so that data written to writehandle appears on (i.e., can be read from) readhandle. This can be used to pass data between separate processes, see event:spawn() or os.spawn(). The pipe itself persists until all its associated descriptors are closed.

A pipe whose read or write end has been closed is considered widowed. Writing on such a pipe causes the write to return a broken pipe error. Widowing a pipe is the only way to deliver end-of-file to a reader: after the reader consumes any buffered data, reading a widowed pipe returns a zero count.

A similar object which supports passing data in both directions is a socketpair.

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