package channel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Functor to create a CHANNEL from a V1_LWT.FLOW implementation

Parameters

module F : V1_LWT.FLOW

Signature

include V1_LWT.CHANNEL with type flow = F.flow
type buffer = Cstruct.t

The type for memory buffers.

type flow = F.flow

The type for unbuffered network flow.

type t

The type for the state associated with channels, such as the inflight buffers.

type 'a io = 'a Lwt.t

The type for potentially blocking I/O operation

type 'a io_stream = 'a Lwt_stream.t

The type for potentially blocking stream of IO requests.

val create : flow -> t

create flow will allocate send and receive buffers and associated them with the given unbuffered flow.

val to_flow : t -> flow

to_flow t will return the flow that backs this channel.

val read_char : t -> char io

Read a single character from the channel, blocking if there is no immediately available input data.

val read_until : t -> char -> (bool * buffer) io

read_until t ch will read from the channel until the given ch character is found. It returns a tuple indicating whether the character was found at all (false indicates that an EOF condition occurred before the character was encountered), and the buffer pointing to the position immediately after the character (or the complete scanned buffer if the character was never encountered).

val read_some : ?len:int -> t -> buffer io

read_some ?len t will read up to len characters from the input channel and at most a full buffer. If len is not specified, it will read all available data and return that buffer.

val read_stream : ?len:int -> t -> buffer io_stream

read_stream ?len t will return up to len characters as a stream of buffers. This call will probably be removed in a future revision of the API in favour of read_some.

val read_line : t -> buffer list io

read_line t will read a line of input, which is terminated either by a CRLF sequence, or the end of the channel (which counts as a line).

  • returns

    Returns a list of views that terminates at EOF.

val write_char : t -> char -> unit

write_char t ch writes a single character to the output channel.

val write_string : t -> string -> int -> int -> unit

write_string t buf off len writes len bytes from a string buf, starting from from offset off.

val write_buffer : t -> buffer -> unit

write_buffer t buf will copy the buffer to the channel's output buffer. The buffer should not be modified after being written, and it will be recycled into the buffer allocation pool at some future point.

val write_line : t -> string -> unit

write_line t buf will write the string buf to the output channel and append a newline character afterwards.

val flush : t -> unit io

flush t will flush the output buffer and block if necessary until it is all written out to the flow.

val close : t -> unit io

close t will call flush and then close the underlying flow.

exception Read_error of F.error
exception Write_error of F.error
val read_exactly : len:int -> t -> Cstruct.t list io

read_exactly len t reads len bytes from the channel t or fails with Read_error or End_of_file.