Module Tcp

module Tcp: sig .. end
with_connection ~host ~port f looks up host from a string (using DNS as needed), connects, then calls f passing in a reader and a writer for the connected socket. When the deferred returned by f is determined, or any exception is thrown, the socket (and reader and writer) are closed. The return deferred is fulfilled after f has finished processing and the file descriptor for the socket is closed. If interrupt is supplied then the connection attempt will be aborted if interrupt is fulfilled before the connection has been established. Similarly, all connection attempts have a timeout (default 30s), that can be overridden with timeout.

type [< Import.Socket.Address.t ] where_to_connect 
val to_host_and_port : string -> int -> Import.Socket.Address.Inet.t where_to_connect
val to_file : string -> Import.Socket.Address.Unix.t where_to_connect
type 'a with_connect_options = ?buffer_age_limit:[ `At_most of Core.Std.Time.Span.t | `Unlimited ] ->
?interrupt:unit Import.Deferred.t ->
?reader_buffer_size:int -> ?timeout:Core.Std.Time.Span.t -> 'a
val with_connection : ([< Import.Socket.Address.t ] where_to_connect ->
(Import.Reader.t -> Import.Writer.t -> 'a Import.Deferred.t) ->
'a Import.Deferred.t)
with_connect_options
with_connection ~host ~port f looks up host from a string (using DNS as needed), connects, then calls f passing in a reader and a writer for the connected socket. When the deferred returned by f is determined, or any exception is thrown, the socket (and reader and writer) are closed. The return deferred is fulfilled after f has finished processing and the file descriptor for the socket is closed. If interrupt is supplied then the connection attempt will be aborted if interrupt is fulfilled before the connection has been established. Similarly, all connection attempts have a timeout (default 30s), that can be overridden with timeout.
val connect_sock : ([< Import.Socket.Address.t ] as 'a) where_to_connect ->
([ `Active ], 'a) Import.Socket.t Import.Deferred.t
connect_sock ~host ~port opens a TCP connection to the specified hostname and port, returning the socket.

Any errors in the connection will be reported to the monitor that was current when connect was called.

val connect : ([< Import.Socket.Address.t ] where_to_connect ->
(Import.Reader.t * Import.Writer.t) Import.Deferred.t)
with_connect_options
module Where_to_listen: sig .. end
A Where_to_listen describes the socket that a tcp server should listen on.
val on_port : int -> Where_to_listen.inet
val on_port_chosen_by_os : Where_to_listen.inet
val on_file : string -> Where_to_listen.unix
module Server: sig .. end
A Server.t represents a TCP server listening on a socket.
val ounit_tests : unit -> OUnit.test

with_connection ~host ~port f looks up host from a string (using DNS as needed), connects, then calls f passing in a reader and a writer for the connected socket. When the deferred returned by f is determined, or any exception is thrown, the socket (and reader and writer) are closed. The return deferred is fulfilled after f has finished processing and the file descriptor for the socket is closed. If interrupt is supplied then the connection attempt will be aborted if interrupt is fulfilled before the connection has been established. Similarly, all connection attempts have a timeout (default 30s), that can be overridden with timeout.

connect_sock ~host ~port opens a TCP connection to the specified hostname and port, returning the socket.

Any errors in the connection will be reported to the monitor that was current when connect was called.

A Where_to_listen describes the socket that a tcp server should listen on.

A Server.t represents a TCP server listening on a socket.

create where_to_listen handler starts a server listening to a socket as specified by where_to_listen. It returns a server once the socket is ready to accept connections. The server calls handler (address, reader, writer) for each client that connects. If the deferred returned by handler is ever determined, or handler raises an exception, then reader and writer are closed.

max_pending_connections is the maximum number of clients that can have a connection pending, as with Unix.Socket.listen. Additional connections will be rejected.

max_connections is the maximum number of clients that can be connected simultaneously. The server will not call accept unless the number of clients is less than max_connections, although of course potential clients can have a connection pending.

buffer_age_limit passes on to the underlying writer option of the same name.

on_handler_error determines what happens if the handler throws an exception. The default is `Raise. If an exception is raised by on_handler_error (either explicitely via `Raise, or in the closure passed to `Call) no further connections will be accepted.

The server will stop accepting and close the listening socket when an error handler raises (either via `Raise or `Call f where f raises), or if close is called.