Module Net.IO

The Io module contains the IO implementation for cohttp-lwt-unix.

The Logs source name for this module logger is "cohttp.lwt.io". Refer to the Debug module for further details.

include Cohttp_lwt.S.IO with type ic = Lwt_io.input_channel and type oc = Lwt_io.output_channel and type conn = Conduit_lwt_unix.flow and type error = exn
include Cohttp.S.IO with type 'a t = 'a Lwt.t with type ic = Lwt_io.input_channel with type oc = Lwt_io.output_channel with type conn = Conduit_lwt_unix.flow
type 'a t = 'a Lwt.t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val return : 'a -> 'a t
type ic = Lwt_io.input_channel
type oc = Lwt_io.output_channel
type conn = Conduit_lwt_unix.flow
val read_line : ic -> string option t
val read : ic -> int -> string t
val write : oc -> string -> unit t
val flush : oc -> unit t
type error = exn
val catch : (unit -> 'a t) -> ('a, error) Stdlib.result t

catch f is f () >|= Result.ok, unless f fails with an IO error, in which case it returns the error.

val pp_error : Stdlib.Format.formatter -> error -> unit
val wait_eof_or_closed : conn -> ic -> (unit -> unit t) -> unit t

wait_eof_or_closed conn ic sleep_fn waits for an EOF or a Closed status on the input channel ic. This function is designed to be used in Lwt.pick to run concurrently with the request handling from the input channel. The function checks for EOF using MSG_PEEK on the input channel without consuming data, thereby not disturbing the request handling. If the connection is closed locally, Cohttp will stop waiting for EOF and will wait the promise to be cancelled. This function ensures that the monitoring does not spin too quickly and uses CPU efficiently when the input channel has read activity but the client is not reading it.

sleep_fn is a parameter function used to yield control periodically, keeping Cohttp platform-independent.