Low-level TCP/SSL socket abstraction with Thrift framed transport.
NebulaGraph uses 4-byte big-endian length-prefixed framing over plain TCP
(or TLS). This module owns the socket lifecycle and provides send_frame/2
and recv_frame/2 which handle the framing transparently.
Callers (i.e. NebulaGraphEx.Connection) should not use raw socket calls —
always go through this module so framing and SSL are handled uniformly.
Summary
Functions
Closes the socket. Works for both plain TCP and SSL sockets.
Opens a TCP (or TLS) connection to host:port.
Receives one complete Thrift frame from the socket.
Sends a binary payload as a single Thrift frame.
Returns true if the socket is an SSL socket.
Types
@type opts() :: keyword()
@type socket() :: :gen_tcp.socket() | :ssl.sslsocket()
Functions
@spec close(socket()) :: :ok
Closes the socket. Works for both plain TCP and SSL sockets.
@spec connect(String.t(), :inet.port_number(), opts()) :: {:ok, socket()} | {:error, term()}
Opens a TCP (or TLS) connection to host:port.
Options
:ssl—boolean, enable TLS. Default:false.:ssl_opts— keyword list passed to:ssl.connect/4. Default:[].:connect_timeout— timeout in ms. Default:5_000.:send_timeout— socket-level send timeout. Default:15_000.
Returns {:ok, socket} or {:error, reason}.
Receives one complete Thrift frame from the socket.
Reads the 4-byte length header first, then reads exactly that many bytes.
Returns {:ok, payload} or {:error, reason}.
Sends a binary payload as a single Thrift frame.
Prepends the 4-byte big-endian length header automatically.
Returns true if the socket is an SSL socket.