module Server:Asig
..end
Server.t
represents a TCP server listening on a socket.type ([< Import.Socket.Address.t ], 'listening_on)
t
typeinet =
(Import.Socket.Address.Inet.t, int) t
typeunix =
(Import.Socket.Address.Unix.t, string) t
val invariant : ([< Import.Socket.Address.t ], 'a) t -> unit
val listening_on : ([< Import.Socket.Address.t ], 'listening_on) t -> 'listening_on
val close : ([< Import.Socket.Address.t ], 'a) t -> unit Import.Deferred.t
val close_finished : ([< Import.Socket.Address.t ], 'a) t -> unit Import.Deferred.t
val is_closed : ([< Import.Socket.Address.t ], 'a) t -> bool
val create : ?max_connections:int ->
?max_pending_connections:int ->
?buffer_age_limit:Import.Writer.buffer_age_limit ->
?on_handler_error:[ `Call of
([< Import.Socket.Address.t ] as 'a) -> exn -> unit
| `Ignore
| `Raise ] ->
('a, 'listening_on) Tcp.Where_to_listen.t ->
('a -> Import.Reader.t -> Import.Writer.t -> unit Import.Deferred.t) ->
('a, 'listening_on) t Import.Deferred.t
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.