package duppy

  1. Overview
  2. Docs
type socket
type marker =
  1. | Length of int
  2. | Split of string

Type for markers. * * Split s recognizes all regexp allowed by the * Pcre module.

type bigarray = (char, Stdlib.Bigarray.int8_unsigned_elt, Stdlib.Bigarray.c_layout) Stdlib.Bigarray.Array1.t

Type of Bigarray used here.

type failure =
  1. | Io_error
  2. | Unix of Unix.error * string * string
  3. | Unknown of exn
  4. | Timeout

Different types of failure. * * Io_error is raised when reading or writing * returned 0. This usually means that the socket * was closed.

val read : ?recursive:bool -> ?init:string -> ?on_error:((string * failure) -> unit) -> ?timeout:float -> priority:'a -> 'a scheduler -> socket -> marker -> ((string * string option) -> unit) -> unit

Wrapper to perform a read on a socket and trigger a function when * a marker has been detected, or enough data has been read. * It reads recursively on a socket, splitting into strings seperated * by the marker (if any) and calls the given function on the list of strings. * * Can be used recursively or not, depending on the way you process strings. * Because of Unix's semantic, it is not possible to stop reading * at first marker, so there can be a remaining string. If not used * recursively, the second optional argument may contain a remaining * string. You should then initiate the next read with this value. * * The on_error function is used when reading failed on the socket. * Depending on your usage, it can be a hard failure, or simply a lost client. * The string passed to on_error contains data read before error * occured. *

  • parameter recursive

    recursively read and process, default: true *

    @param init

    initial string for reading, default: "" *

    @param on_error

    function used when read failed, default: fun _ -> () *

    @param timeout

    Terminate with Timeout failure if nothing has been read * after the given amout of time in seconds. More precisely, * the exception is raised when no character have been read * and the socket was not close while waiting. Default: wait * forever.

val write : ?exec:(unit -> unit) -> ?on_error:(failure -> unit) -> ?bigarray:bigarray -> ?offset:int -> ?length:int -> ?string:Stdlib.Bytes.t -> ?timeout:float -> priority:'a -> 'a scheduler -> socket -> unit

Similar to read but less complex. * write ?exec ?on_error ?string ?bigarray ~priority scheduler socket * write data from string, or from bigarray if no string is given, * to socket, and executes exec or on_error if errors occured. * * Caveat: on Win32, all file descriptors are expected to be in blocking * mode before being passed to this call due to limitations in the emulation * of the unix/posix API. See code comments for more details. * *

  • parameter exec

    function to execute after writing, default: fun () -> () *

    @param on_error

    function to execute when an error occured, default: fun _ -> () *

    @param string

    write data from this string *

    @param bigarray

    write data from this bigarray, if no string is given *

    @param timeout

    Terminate with Timeout failure if nothing has been written * after the given amout of time in seconds. More precisely, * the exception is raised when no character have been written * and the socket was not close while waiting. Default: wait * forever.

OCaml

Innovation. Community. Security.