Module Neodriver_eio.Transport

Eio-based TCP transport with Bolt message framing.

Eio-based TCP transport with Bolt message framing.

See transport.ml for the implementation.

type t

A TCP transport with a bounded read/write timeout and Bolt chunk framing.

type tls_mode =
  1. | Plain
  2. | Verify of string
  3. | Trust_all of string
    (*

    How the connection is secured with TLS:

    • Plain: no TLS.
    • Verify host: wrap the connection in TLS, validating the server certificate against the system trust store and checking host (bolt+s).
    • Trust_all host: wrap the connection in TLS without validating the server certificate (bolt+ssc).
    *)
val connect : [> `Network | `Platform of [> `Generic ] ] Eio.Resource.t -> Eio.Switch.t -> ?timeout:Eio.Time.Timeout.t -> ?tls:tls_mode -> Neodriver_core.Addressing.t -> (t, Neodriver_core.Errors.t) Stdlib.result

Open a TCP connection to address (resolving host names as needed) and return a transport. Each resolved address (IPv4 and IPv6) is tried in turn until one connects. If tls is Verify _ or Trust_all _, the connection is wrapped in TLS before returning. The TCP connect and TLS handshake share a single timeout deadline; reads/writes on the result are bounded by the same deadline. The default (Eio.Time.Timeout.none) imposes no deadline.

  • returns

    Error _ if the address cannot be resolved, if every resolved address fails to connect or complete the TLS handshake (all failures are aggregated into the Service_unavailable message), or if the operation times out.

val read_exact : t -> Stdlib.Bytes.t -> int -> int -> (unit, Neodriver_core.Errors.t) Stdlib.result

Read exactly len bytes into buf starting at offset off.

  • returns

    Error _ on timeout or end-of-file.

val write : t -> Stdlib.Bytes.t -> (unit, Neodriver_core.Errors.t) Stdlib.result

Write buf to the connection.

  • returns

    Error _ on timeout or write failure.

val write_message : t -> Stdlib.Bytes.t -> (unit, Neodriver_core.Errors.t) Stdlib.result

Write a Bolt message, splitting it into 16 KiB chunks prefixed by their size and terminated by a 0x0000 chunk.

val read_message : t -> (Stdlib.Bytes.t, Neodriver_core.Errors.t) Stdlib.result

Read one Bolt message, reassembling its chunks and skipping NOOP (empty) messages.

  • returns

    Error _ on timeout or end-of-file.

val close : t -> unit

Close the connection.