Module Lwt_io

module Lwt_io : sig..end

Buffered byte channels

A channel is a high-level object for performing input/output (IO). It allows to read/write from/to the outside world in an efficient way, by minimising the number of system calls.

An output channel is used to send data and an input channel is used to receive data.

If you are familiar with buffered channels you may be familiar too with the flush operation. Note that byte channels of this module are automatically flushed when there is nothing else to do (i.e. before the program becomes idle), so this means that you no longer have to write:

eprintf "log message\n";
      flush stderr;

to have your messages displayed.

Note about errors: input functions of this module raise End_of_file when the end-of-file is reached (i.e. when the read function returns 0). Other exceptions are ones caused by the backend read/write functions, such as Unix.Unix_error.

exception Channel_closed of string

Exception raised when a channel is closed. The parameter is a description of the channel.


type 'mode channel

Type of buffered byte channels

type input

Input mode

type output

Output mode

type 'a mode =  | Input | Output

Channel mode

val input : input mode

input input mode representation

val output : output mode

output output mode representation

type input_channel = input channel

Type of input channels

type output_channel = output channel

Type of output channels

val mode : 'a channel -> 'a mode

mode ch returns the mode of a channel

Well-known instances

val stdin : input_channel

The standard input, it reads data from Lwt_unix.​stdin

val stdout : output_channel

The standard output, it writes data to Lwt_unix.​stdout

val stderr : output_channel

The standard output for error messages, it writes data to Lwt_unix.​stderr

val zero