Monad.MakeIotype socket = Io.socketmodule Io = Iotype ('a, 'b) handler = {scheduler : 'a scheduler;socket : Io.socket;mutable data : string;on_error : Io.failure -> 'b;}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.
exec ?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.
delay ~priority h d creates a computation that returns * unit after delay d in seconds.
read ?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 scheduler ->
Io.socket ->
(string, string * Io.failure) 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 ->
?offset:int ->
?length:int ->
Stdlib.Bytes.t ->
(unit, 'b) 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) 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.