Dllb.Connection (Dllb v0.1.0)

Copy Markdown View Source

Raw TCP socket operations for communicating with a dllb server.

This module is not a GenServer. It provides stateless functions that operate on a :gen_tcp socket, suitable for use inside a connection pool or standalone.

Summary

Functions

Checks whether the socket is still open.

Closes the TCP socket.

Opens a TCP connection to the dllb server and sends the OUTCOME command.

Sends a query over an established socket and returns the parsed result.

Types

opts()

@type opts() :: [
  host: String.t() | charlist(),
  port: :inet.port_number(),
  outcome: Dllb.Protocol.format(),
  timeout: timeout()
]

Functions

alive?(socket)

@spec alive?(:gen_tcp.socket()) :: boolean()

Checks whether the socket is still open.

Uses :inet.peername/1 to determine connectivity without consuming data from the socket.

close(socket)

@spec close(:gen_tcp.socket()) :: :ok

Closes the TCP socket.

connect(opts \\ [])

@spec connect(opts()) :: {:ok, :gen_tcp.socket()} | {:error, term()}

Opens a TCP connection to the dllb server and sends the OUTCOME command.

Options

  • :host - server hostname (default "127.0.0.1")
  • :port - server port (default 3009)
  • :outcome - response format, one of :json, :toon, :csv (default :json)
  • :timeout - connection and recv timeout in ms (default 30_000)

Returns {:ok, socket} or {:error, reason}.

query(socket, query_string, opts \\ [])

@spec query(:gen_tcp.socket(), String.t(), Keyword.t()) ::
  {:ok, Dllb.Result.t()} | {:error, term()}

Sends a query over an established socket and returns the parsed result.

Options

  • :timeout - recv timeout in ms (default 30_000)
  • :outcome - response format (default :json)

Returns {:ok, result} or {:error, reason}.