module Netsys_polysocket:sig
..end
type'a
polyendpoint ='a Netsys_polypipe.polypipe * 'a Netsys_polypipe.polypipe
(rd,wr)
where rd
is a polypipe open
for reading, and wr
is a polypipe open for writing.type 'a
polyclient
type 'a
polyserver
val create_client : int -> 'a polyclient
val connect : 'a polyclient -> 'a polyserver -> unit
Possible Unix.unix_error
codes:
EALREADY
EISCONN
val endpoint : synchronous:bool ->
nonblock:bool ->
'a polyclient -> 'a polyendpoint
nonblock
is true, the Unix_error
EAGAIN
is returned if such waiting
is needed.
Possible Unix.unix_error
codes:
EAGAIN
: the client is non-blocking, and the connection is not yet
establishedEINTR
: a signal arrivedECONNREFUSED
: the server went down in the meantimeENOTCONN
: no previous connect
val close_client : 'a polyclient -> unit
Netsys_polypipe.Closed
.val set_connect_notify : 'a polyclient -> (unit -> unit) -> unit
set_connect_notify cl f
: Sets that the function f
is called when
the connection is accepted. There can only be one such function; any
previous function is overwritten. Only future connect events are
reported. The function is called from a different thread.val connect_descr : 'a polyclient -> Unix.file_descr
endpoint
again is promising.
If connect_descr
is called several times, always the same descriptor is
returned.
The caller has to close the descriptor after use.
You can call this function only after connect
.
val create_server : unit -> 'a polyserver
Note that a server needs 2-6 file descriptors in the current
implementation.
val accept : nonblock:bool ->
'a polyserver -> 'a polyendpoint
Possible Unix.unix_error
codes:
EAGAIN
: the server is non-blocking, and no connection attempt is
pendingEINTR
: a signal arrivedval refuse : nonblock:bool -> 'a polyserver -> unit
ECONNREFUSED
. It is possible to return to accepting connections.
For a non-blocking refuse
you need to call refuse
again after
catching EAGAIN
.
val pending_connection : 'a polyserver -> bool
val close_server : 'a polyserver -> unit
Further interactions with the server cause that the exception
Netsys_polypipe.Closed
will be raised.
val set_accept_notify : 'a polyserver -> (unit -> unit) -> unit
set_accept_notify srv f
: Sets that the function f
is called when
a new connection arrives. There can only be one such function; any
previous function is overwritten. The event is edge-triggered: when
several connections arrive the function is only called once. The
function is called from a different thread.val accept_descr : 'a polyserver -> Unix.file_descr
The caller has to close the descriptor after use.
You can call this function before or after accept
.