package duppy

  1. Overview
  2. Docs
type socket = Unix.file_descr
module Io = Io

Type

type ('a, 'b) handler = {
  1. scheduler : 'a scheduler;
  2. socket : Io.socket;
  3. mutable data : string;
  4. 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.

Execution flow

val exec : ?delay:float -> priority:'a -> ('a, 'b) handler -> ('c, 'b) t -> ('c, 'b) t

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.

val delay : priority:'a -> ('a, 'b) handler -> float -> (unit, 'b) t

delay ~priority h d creates a computation that returns * unit after delay d in seconds.

Read/write

val read : ?timeout:float -> priority:'a -> marker:Io.marker -> ('a, 'b) handler -> (string, 'b) t

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) t

read_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 -> Bytes.t -> (unit, 'b) t

write ?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) t

write_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.

OCaml

Innovation. Community. Security.