package octez-shell-libs
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=aa2f5bc99cc4ca2217c52a1af2a2cdfd3b383208cb859ca2e79ca0903396ca1d
sha512=d68bb3eb615e3dcccc845fddfc9901c95b3c6dc8e105e39522ce97637b1308a7fa7aa1d271351d5933febd7476b2819e1694f31198f1f0919681f1f9cc97cb3a
doc/octez-shell-libs.p2p/Tezos_p2p/P2p_fd/index.html
Module Tezos_p2p.P2p_fd
Source
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 close_reason = [
| `Connection_closed_by_peer
| `Connection_locally_closed
| `Connection_lost of exn
| `Unexpected_error of exn
| `Unexpected_error_when_closing of exn * exn
]
type listening_socket_open_failure = {
reason : Unix.error;
(*The error we are re-raising
*)address : Tezos_base.TzPervasives.P2p_addr.t;
(*The interface we are trying to listen to
*)port : int;
(*The port we are trying to listen to
*)
}
Type describing an opening failure for the listening socket.
type Tezos_base.TzPervasives.error +=
| Failed_to_open_listening_socket of listening_socket_open_failure
Type of an error in case of the listening socket fails to open.
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.
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.
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 ]) 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.