module Netsys_polypipe:sig..end
Polymorphic message pipes
These pipes are restricted to a single process, and can be used to send messages of any types between threads.
exception Closed
type 'a polypipe
val create : int -> 'a polypipe * 'a polypipeCreate a new polypipe with an internal buffer of n messages. The left descriptor is open for reading, and the right is open for writing.
val length : 'a polypipe -> intreturn the number of messages in the buffer
val eof : 'a polypipe -> boolwhether the eof marker was sent. Note that there may still be messages in the buffer
val read : nonblock:bool -> 'a polypipe -> 'a optionread a message. None means EOF. Possible Unix.unix_error codes:
EAGAIN: the pipe is non-blocking, and there is no message in the
bufferEINTR: a signal arrivedRaises Closed if the polypipe has been closed.
val write : nonblock:bool -> 'a polypipe -> 'a option -> unitwrite a message, or mark the end of the stream (None).
Possible Unix.unix_error codes:
EAGAIN: the pipe is non-blocking, and there is no message in the
bufferEINTR: a signal arrivedEPIPE: it was tried to send a message after sending None.Unlike OS pipes, polypipes become writable after signaling EOF.
Raises Closed if the polypipe has been closed.
val close : 'a polypipe -> unitClose the pipe. Writing will be immediately impossible. Reading
will return None.
val set_read_notify : 'a polypipe -> (unit -> unit) -> unitset_read_notify pipe f: Sets that the function f is called
when the pipe becomes readable (or reaches eof). Only one such
function can be registered; any previous function is
overwritten. The function will be called from a different thread.
val set_write_notify : 'a polypipe -> (unit -> unit) -> unitset_write_notify pipe f: Sets that the function f is called
when the pipe becomes writable (or reaches eof). Only one such
function can be registered; any previous function is
overwritten. The function will be called from a different thread.
val read_descr : 'a polypipe -> Unix.file_descrReturns a descriptor that can be used for polling. When the descriptor is readable there is a message in the buffer. If called several times, always the same descriptor is returned.
The caller has to close the descriptor after use.
Raises Closed if the polypipe has been closed.
val write_descr : 'a polypipe -> Unix.file_descrReturns a descriptor that can be used for polling. When the descriptor is readable (sic) there is space in the buffer for another message. If called several times, always the same descriptor is returned.
The caller has to close the descriptor after use.
Raises Closed if the polypipe has been closed.
val set_exception : 'a polypipe -> exn -> unitSets an exception that is returned by further calls of
write. If an exception already exists, it is not overwritten.
read will return EOF. Readers need to test for the exceptionw with
get_exception.
val get_exception : 'a polypipe -> exn optionGet the exception
module Debug:sig..end