package tezos-p2p

  1. Overview
  2. Docs

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
]
val pp_close_reason : 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) 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 ]) result Lwt.t

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

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.

Returns a fresh fd. This call always succeed.

val connect : t -> Lwt_unix.sockaddr -> (unit, [ `Unexpected_error of exn | `Connection_refused ]) 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 ]) 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.