module Tcp:sig..end
TCP handles are used to represent both TCP streams and servers.
type t
include Uwt.Stream
include Uwt.Handle_ext
include Uwt.Handle_fileno
val to_stream : t -> Uwt.Stream.t
val init : unit -> tSee comment to Uwt.Pipe.init
val init_ipv4 : unit -> t uv_resultwrappers around uv_tcp_init_ex. A socket of the given type will be
created immediately instead of lazy (as with Uwt.Tcp.init)
val init_ipv4_exn : unit -> t
val init_ipv6 : unit -> t uv_result
val init_ipv6_exn : unit -> t
val opentcp : Unix.file_descr -> t uv_resultSee comment to Uwt.Pipe.openpipe
val opentcp_exn : Unix.file_descr -> t
type mode =
| |
Ipv6_only |
val bind : ?mode:mode list ->
t -> addr:sockaddr -> unit -> Int_result.unitBind the handle to an address and port.
When the port is already taken, you can expect to see an
EADDRINUSE error from either Uwt.Tcp.bind, listen or
Uwt.Tcp.connect. That is, a successful call to this function does not
guarantee that the call to listen or Uwt.Tcp.connect will succeed
as well.
val bind_exn : ?mode:mode list -> t -> addr:sockaddr -> unit -> unit
val nodelay : t -> bool -> Int_result.unitEnable TCP_NODELAY, which disables Nagle's algorithm.
val nodelay_exn : t -> bool -> unit
val enable_keepalive : t -> int -> Int_result.unitenable_keepalive tcp delay enables keep-alive, the delay is the
initial delay in seconds
val enable_keepalive_exn : t -> int -> unit
val disable_keepalive : t -> Int_result.unit
val disable_keepalive_exn : t -> unit
val simultaneous_accepts : t -> bool -> Int_result.unitEnable / disable simultaneous asynchronous accept requests that are queued by the operating system when listening for new TCP connections.
This setting is used to tune a TCP server for the desired performance. Having simultaneous accepts can significantly improve the rate of accepting connections (which is why it is enabled by default) but may lead to uneven load distribution in multi-process setups.
val simultaneous_accepts_exn : t -> bool -> unit
val getsockname : t -> sockaddr uv_resultGet the current address to which the handle is bound.
val getsockname_exn : t -> sockaddr
val getpeername : t -> sockaddr uv_resultGet the address of the peer connected to the handle.
val getpeername_exn : t -> sockaddr
val connect : t -> addr:sockaddr -> unit Lwt.tEstablish an IPv4 or IPv6 TCP connection.
val accept : t -> t uv_resultinitializes a new client, accepts and returns it.
This call is used in conjunction with listen to accept
incoming connections. Call this function after receiving a
listen callback to accept the connection.
When the listen callback is called it is guaranteed
that this function will complete successfully the first time. If
you attempt to use it more than once, it may fail. It is
suggested to only call this function once per listen callback
call.
val accept_exn : t -> t
val with_tcp : (t -> 'a Lwt.t) -> 'a Lwt.tSee comments to Uwt.Pipe.with_pipe
val with_connect : addr:sockaddr -> (t -> 'a Lwt.t) -> 'a Lwt.t
val with_open : Unix.file_descr -> (t -> 'a Lwt.t) -> 'a Lwt.t
val with_accept : t -> (t -> 'a Lwt.t) -> 'a Lwt.t
val accept_raw : server:t -> client:t -> Int_result.unit
val accept_raw_exn : server:t -> client:t -> unit