Funix
Fiber friendly Unix
functions.
Clients of these functions need to be run in a Fiber.run
function called with Funix.unblock
.
val unblock : Fiber.unblock
unblock
is the function to unblock fibers blocked by the function of this module. You must use this function with Fiber.run
.
module Signal : sig ... end
Signals
If the file descriptor is in non-blocking mode, these functions block the fiber, not the domain thread.
read fd b ~start ~len
reads len
bytes from fd
into b
starting at start
and returns true
. Returns false
if len
bytes could not be read (i.e. end of file/stream was hit). The function handles signal interruptions (EINTR
) by retrying.
write fd b ~start ~len
writes len
bytes starting at start
from b
on fd
. The function handles signal interruptions (EINTR
) by retrying.
accept fd
is a fiber friendly Unix.accept
which returns file descriptors is in non-blocking mode. The function handles signal interruptions (EINTR
) by retrying.
connect fd addr
is a fiber friendly Unix.connect
. The function handles signal interruptions (EINTR
) by retrying.
close_noerr fd
closes fd
and ignores any error. Useful for Fun.protect
finally
functions which must not raise.
type endpoint = [
| `Host of string * int
Hostname and port.
*)| `Sockaddr of Unix.sockaddr
Given socket address.
*)| `Fd of Unix.file_descr
Direct file descriptor.
*) ]
The type for specifying a socket endpoint to connect to or to listen to on.
val endpoint_of_string :
default_port:int ->
string ->
(endpoint, string) Stdlib.result
connection_of_string ~default_port s
parses a connection specification from s
. The format is ADDR[:PORT]
or PATH
for a Unix domain socket (detected by the the presence of a directory separator). default_port
port is used if no PORT
is specified.
val pp_endpoint : Stdlib.Format.formatter -> endpoint -> unit
pp_socket_endpoint
formats an unspecified representation of endpoint values.
val socket_of_endpoint :
endpoint ->
Unix.socket_type ->
(Unix.sockaddr option * Unix.file_descr * bool, string) Stdlib.result
socket_of_endpoint c
is Ok (addr, fd, close)
with:
addr
, the address for the socket, if any.fd
, the file descriptor for the socket. If c
is `Fd fd
this fd
untouched. Otherwise fd
is a new file descriptor set to non-blocking mode and has close on exec set to true
.close
is true
if the caller is in charge of closing it. This is false
iff c
is `Fd _
.