package affect

  1. Overview
  2. Docs

Module Net.ConnectionSource

Network connections.

Connections

Sourcetype t

The type for connections.

Sourceval open' : ?nonblock:bool -> ?socket_type:Unix.socket_type -> peer:Endpoint.t -> unit -> (t, string) result

open ~peer () opens a connection to a peer listening on peer with:

  • nonblock if true the socket is in non-blocking mode (default).
  • socket_type is the type of connection. Defaults to Unix.socket_type.SOCK_STREAM or the fd's type if peer is `Fd fd – if socket_type is specified in this case this errors if fd is not of the specified type.
  • If a new file descriptor is created, it is with cloexec set to true.
  • If peer is `Fd fd it is assumed to be connected. So the call just tries to honour the nonblock argument and gets it's peer and local address from the fd. Also note that in this case close_noerr does not close fd it's your duty to do so.

If a connection is returned it must always eventually be closed with close_noerr.

Sourceval try_open : ?nonblock:bool -> ?socket_type:Unix.socket_type -> peer:Endpoint.t -> unit -> (t option, string) result

try_open ~endpoint is like open' except None is returned if Unix.connect errors with ENOENT, ECONNREFUSED or EHOSTUNREACH.

Sourceval close_noerr : t -> unit

close_noerr c closes c without raising errors and can be safely called repeatedly. Note that if peer c is `Fd fd this does not close fd.

Properties

fd c is the file descriptor of c.

Sourceval peer : t -> Endpoint.t

peer c is the peer of c.

Sourceval peer_addr : t -> Unix.sockaddr

peer_addr c is the peer address for c.

Sourceval our_addr : t -> Unix.sockaddr

our_addr c is our address for c.

Sourceval socket_type : t -> Unix.socket_type

socket_type c is the socket type of c.

Formatting

Sourceval error : t -> string -> string

error c msg formats an error message for connection c.

Sourceval pp : Format.formatter -> t -> unit

pp formats connections for inspection.

Sourceval pp_debug : Format.formatter -> t -> unit

pp_debug formats connection for more inspection.