package simple_httpd

  1. Overview
  2. Docs

Module Simple_httpd.IoSource

Module that encapsulates non blocking sockets with function similar to Unix.read and Unix.single_write but that will perform scheduling instead of blocking. This can be used to access your database. It has been tested with OCaml's bindings to libpq.

Io can be shared across several clients, for instance clients using the same session. As always, be aware of protecting concurrent access to the socket, as different client may run simultaneously on different domain.

Io is completely useless on regular file or blocking sockets.

Sourcetype t
Sourceval create : ?edge_triggered:bool -> ?finalise:(t -> unit) -> ?client:Client.t -> Unix.file_descr -> t

Encapsulate a file descriptor in a dedicated data structure. finalise default to Unix.close Io.sock.

If client is provided, the ressource is atatched to the client and destroyed (call to finalise) when the client is closed.

Not suitable for file descriptor using SSL, unless kernel tls is used.

Sourceval close : t -> unit

Close io, similar to Unix.close, simply call finalise

Sourceval read : t -> Bytes.t -> int -> int -> int

Read, similar to Unix.read, but asynchronous

Sourceval write : t -> Bytes.t -> int -> int -> int

Read, similar to Unix.write, but asynchronous

Sourceval sock : t -> Unix.file_descr

Returns the socket, usefull in finalise or to set some socket properties, do not attempt to read/write the socket.

Sourceval formatter : t -> Format.formatter

Provide a formatter to use with the Format library

Sourceval schedule : bool -> t -> unit

Allow to schedule the io immediatly. Typical use is opening a pipe and waiting the other end to be ready. The boolean should be true for read,