package octez-shell-libs

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

This module defines a type t which wraps a file descriptor. Most functions simply call the underlying file descriptor function and generate logs with prefix "p2p.fd".

type t
type close_reason = [
  1. | `Connection_closed_by_peer
  2. | `Connection_locally_closed
  3. | `Connection_lost of exn
  4. | `Unexpected_error of exn
  5. | `Unexpected_error_when_closing of exn * exn
]
type listening_socket_open_failure = {
  1. reason : Unix.error;
    (*

    The error we are re-raising

    *)
  2. address : Tezos_base.TzPervasives.P2p_addr.t;
    (*

    The interface we are trying to listen to

    *)
  3. port : int;
    (*

    The port we are trying to listen to

    *)
}

Type describing an opening failure for the listening socket.

type Tezos_base.TzPervasives.error +=
  1. | Failed_to_open_listening_socket of listening_socket_open_failure

Type of an error in case of the listening socket fails to open.

val pp_close_reason : Stdlib.Format.formatter -> close_reason -> unit
val id : t -> int

id t returns a unique, positive, identifier for t. Identifiers are generated sequentially at creation time.

val read : t -> Tezos_base.TzPervasives.Bytes.t -> int -> int -> (int, close_reason) Stdlib.result Lwt.t

read fd buf ofs len reads up to len bytes from fd, and writes them to buf, starting at offset ofs. If the operation leads to a `Connection_lost error it is guaranteed that the underlying socket has been closed.

val close : t -> (unit, [ `Unexpected_error of exn ]) Stdlib.result Lwt.t

close fd close the connection and the underlying fd. It is idempotent.

val write : t -> Tezos_base.TzPervasives.Bytes.t -> (unit, close_reason) Stdlib.result Lwt.t

write fd buf writes all bytes from buf to fd. If the operation leads to a `Connection_lost error it is guaranteed that the underlying socket has been closed.

val socket : unit -> t Lwt.t

Returns a fresh fd. This call always succeed.

val create_listening_socket : ?reuse_port:bool -> backlog:int -> ?addr:Ipaddr.V6.t -> int -> Lwt_unix.file_descr Tezos_base.TzPervasives.tzresult Lwt.t

create_listening_socket ?reuse_port ~backlog ?addr port creates a socket that listens on addr or Ipaddr.V6.unspecified if addr is not provided and on port.

reuse_port is used to set Unix socket option SO_REUSEPORT. If reuse_port is not provided this option is set to false. SO_REUSEADDR is set to true.

backlog set the maximum number of pending connections.

val connect : t -> Lwt_unix.sockaddr -> (unit, [ `Unexpected_error of exn | `Connection_refused ]) Stdlib.result Lwt.t

connect fd addr connect fd to addr.

val accept : Lwt_unix.file_descr -> (t * Lwt_unix.sockaddr, [ `System_error of exn | `Socket_error of exn | `Unexpected_error of exn ]) Stdlib.result Lwt.t

accept sock accept connections on socket sock

This function can fail and raise an error.

`System_error : System-wide errors which are related to the state of whole process or computer. These are errors that will probably reoccur at next call and must be treated accordingly (for example by giving some time to the system to recover).

`Socket_error : Socket-specific errors which are related to the one connection that the function attempted to accept. These are usually temporary errors related to network delays or remote host responsiveness . For most socket-errors you can just log them and call accept again to be ready for the next connection.

`Unexpected_error : These are other types of errors that can arise and not caught by the previous cases.

OCaml

Innovation. Community. Security.