module Io:Monad_io_twith type socket = Unix.file_descr and module Io = Io
type socket
module Io:Duppy.Io_twith type socket = socket
type ('a, 'b) handler = {
|
scheduler : |
|
socket : |
|
mutable data : |
|
on_error : |
A handler for this module
is a record that contains the
required elements. In particular,
on_error is a function that transforms
an error raised by Duppy.Io to a reply
used to terminate the computation.
data is an internal data buffer. It should
be initialized with "". It contains the
remaining data that was received when
using read. If an error occured,
data contain data read before the
error.
val exec : ?delay:float ->
priority:'a ->
('a, 'b) handler ->
('c, 'b) Duppy.Monad.t -> ('c, 'b) Duppy.Monad.texec ?delay ~priority h f redirects computation
f into a new queue with priority priority and
delay delay (0. by default).
It can be used to redirect a computation that
has to run under a different priority. For instance,
a computation that reads from a socket is generally
not blocking because the function is executed
only when some data is available for reading.
However, if the data that is read needs to be processed
by a computation that can be blocking, then one may
use exec to redirect this computation into an
appropriate queue.
val delay : priority:'a ->
('a, 'b) handler -> float -> (unit, 'b) Duppy.Monad.tdelay ~priority h d creates a computation that returns
unit after delay d in seconds.
val read : ?timeout:float ->
priority:'a ->
marker:Io.marker ->
('a, 'b) handler -> (string, 'b) Duppy.Monad.tread ?timeout ~priority ~marker h creates a
computation that reads from h.socket
and returns the first string split
according to marker. This function
can be used to create a computation that
reads data from a socket. timeout parameter
forces the computation to return an error if
nothing has been read for more than timeout
seconds. Default: wait forever.
val read_all : ?timeout:float ->
priority:'a ->
'a Duppy.scheduler ->
Io.socket ->
(string, string * Io.failure) Duppy.Monad.tread_all ?timeout ~priority s sock creates a
computation that reads all data from sock
and returns it. Raised value contains data
read before an error occured.
val write : ?timeout:float ->
priority:'a ->
('a, 'b) handler ->
Stdlib.Bytes.t -> (unit, 'b) Duppy.Monad.twrite ?timeout ~priority h s creates a computation
that writes string s to h.socket. This
function can be used to create a computation
that sends data to a socket. timeout parameter
forces the computation to return an error if
nothing has been written for more than timeout
seconds. Default: wait forever.
val write_bigarray : ?timeout:float ->
priority:'a ->
('a, 'b) handler ->
Io.bigarray -> (unit, 'b) Duppy.Monad.twrite_bigarray ?timeout ~priority h ba creates a computation
that writes data from ba to h.socket. This function
can to create a computation that writes data to a socket.