Module type Duppy.Io_t

Reading and writing a socket from a computation running under run: both park until the socket is ready rather than returning to the scheduler.

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

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

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

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

exception Error of failure

Raised by read and write. On a read, whatever had been read before the failure is left in the handle's data.

type 'a handle = {
  1. scheduler : 'a scheduler;
  2. socket : socket;
  3. mutable data : string;
}

data holds what a read consumed past its marker, which the next read on the same socket picks up.

val handle : 'a scheduler -> socket -> 'a handle
val read : ?timeout:float -> priority:'a -> 'a handle -> marker -> string

read ?timeout ~priority h marker returns the data up to marker, parking the computation until enough of it has arrived.

  • parameter timeout

    applies to each wait rather than to the call. Default: wait forever.

val write : ?timeout:float -> ?offset:int -> ?length:int -> priority:'a -> 'a handle -> Stdlib.Bytes.t -> unit

write ?timeout ~priority h data writes all of data, parking until the socket accepts it.

  • parameter timeout

    applies to each wait rather than to the call. Default: wait forever.