Module Eio_unix.NetSource

Extended network API with support for file descriptors.

Types

These extend the types in Eio.Net with support for file descriptors.

Sourcetype stream_socket_ty = [ `Generic | `Unix ] Eio.Net.stream_socket_ty
Sourcetype datagram_socket_ty = [ `Generic | `Unix ] Eio.Net.datagram_socket_ty
Sourcetype listening_socket_ty = [ `Generic | `Unix ] Eio.Net.listening_socket_ty
Sourcetype 'a stream_socket = [> stream_socket_ty ] as 'a Eio.Std.r
Sourcetype 'a datagram_socket = [> datagram_socket_ty ] as 'a Eio.Std.r
Sourcetype 'a listening_socket = [> listening_socket_ty ] as 'a Eio.Std.r
Sourcetype t = [ `Generic | `Unix ] Eio.Net.ty Eio.Std.r

Passing file descriptors

Sourceval send_msg : [> `Platform of [> `Unix ] | `Socket | `Stream ] Eio.Std.r -> ?fds:Fd.t list -> Cstruct.t list -> unit

Like Eio.Flow.write, but allows passing file descriptors (for Unix-domain sockets).

Sourceval recv_msg_with_fds : [> `Platform of [> `Unix ] | `Socket | `Stream ] Eio.Std.r -> sw:Eio.Std.Switch.t -> max_fds:int -> Cstruct.t list -> int * Fd.t list

Like Eio.Flow.single_read, but also allows receiving file descriptors (for Unix-domain sockets).

  • parameter max_fds

    The maximum number of file descriptors to accept (additional ones will be closed).

Sourceval fd : [> `Platform of [> `Unix ] | `Socket ] Eio.Std.r -> Fd.t

fd socket is the underlying FD of socket.

Unix address conversions

Note: OCaml's Unix.sockaddr type considers e.g. TCP port 80 and UDP port 80 to be the same thing, whereas Eio regards them as separate addresses that just happen to have the same representation (a host address and a port number), so we have separate "of_unix" functions for each.

Sourceval sockaddr_of_unix_stream : Unix.sockaddr -> Eio.Net.Sockaddr.stream
Sourceval sockaddr_of_unix_datagram : Unix.sockaddr -> Eio.Net.Sockaddr.datagram
Sourcemodule Ipaddr : sig ... end

Convert between Eio.Net.Ipaddr and Unix.inet_addr.

Creating or importing sockets

Sourceval import_socket_stream : sw:Eio.Std.Switch.t -> close_unix:bool -> Unix.file_descr -> [< `Unix_fd | stream_socket_ty ] Eio.Std.r

import_socket_stream ~sw ~close_unix fd is an Eio flow that uses fd.

It can be cast to e.g. source for a one-way flow. The socket object will be closed when sw finishes.

The close_unix and sw arguments are passed to Fd.of_unix.

Sourceval import_socket_listening : sw:Eio.Std.Switch.t -> close_unix:bool -> Unix.file_descr -> [< `Unix_fd | listening_socket_ty ] Eio.Std.r

import_socket_listening ~sw ~close_unix fd is an Eio listening socket that uses fd.

The socket object will be closed when sw finishes.

The close_unix and sw arguments are passed to Fd.of_unix.

Sourceval import_socket_datagram : sw:Eio.Std.Switch.t -> close_unix:bool -> Unix.file_descr -> [< `Unix_fd | datagram_socket_ty ] Eio.Std.r

import_socket_datagram ~sw ~close_unix fd is an Eio datagram socket that uses fd.

The socket object will be closed when sw finishes.

The close_unix and sw arguments are passed to Fd.of_unix.

Sourceval socketpair_stream : sw:Eio.Std.Switch.t -> ?domain:Unix.socket_domain -> ?protocol:int -> unit -> [< `Unix_fd | stream_socket_ty ] Eio.Std.r * [< `Unix_fd | stream_socket_ty ] Eio.Std.r

socketpair_stream ~sw () returns a connected pair of flows, such that writes to one can be read by the other.

This creates OS-level resources using socketpair(2). Note that, like all FDs created by Eio, they are both marked as close-on-exec by default.

Sourceval socketpair_datagram : sw:Eio.Std.Switch.t -> ?domain:Unix.socket_domain -> ?protocol:int -> unit -> [< `Unix_fd | datagram_socket_ty ] Eio.Std.r * [< `Unix_fd | datagram_socket_ty ] Eio.Std.r

socketpair_datagram ~sw () returns a connected pair of flows, such that writes to one can be read by the other.

This creates OS-level resources using socketpair(2). Note that, like all FDs created by Eio, they are both marked as close-on-exec by default.

Private API for backends

Sourceval getnameinfo : Eio.Net.Sockaddr.t -> string * string

getnameinfo sockaddr returns domain name and service for sockaddr.

Sourcetype Effect.t +=
  1. | Import_socket_stream : Eio.Std.Switch.t * bool * Unix.file_descr -> [ `Unix_fd | stream_socket_ty ] Eio.Std.r Effect.t
  2. | Import_socket_listening : Eio.Std.Switch.t * bool * Unix.file_descr -> [ `Unix_fd | listening_socket_ty ] Eio.Std.r Effect.t
  3. | Import_socket_datagram : Eio.Std.Switch.t * bool * Unix.file_descr -> [ `Unix_fd | datagram_socket_ty ] Eio.Std.r Effect.t
  4. | Socketpair_stream : Eio.Switch.t * Unix.socket_domain * int -> ([ `Unix_fd | stream_socket_ty ] Eio.Std.r * [ `Unix_fd | stream_socket_ty ] Eio.Std.r) Effect.t
  5. | Socketpair_datagram : Eio.Switch.t * Unix.socket_domain * int -> ([ `Unix_fd | datagram_socket_ty ] Eio.Std.r * [ `Unix_fd | datagram_socket_ty ] Eio.Std.r) Effect.t