Exth.Transport.Ipc (Exth v0.5.0)

View Source

IPC (Inter-Process Communication) transport implementation for JSON-RPC requests using Unix domain sockets.

Implements the Exth.Transport.Transportable protocol for making IPC connections to JSON-RPC endpoints via Unix domain sockets. Uses NimblePool for connection pooling and efficient resource management.

Features

  • Unix domain socket communication
  • Connection pooling with NimblePool
  • Automatic connection management
  • Configurable pool size and timeouts
  • Efficient resource utilization
  • Process registration with via-tuples

Usage

transport = Transportable.new(
  %Exth.Transport.Ipc{},
  path: "/tmp/ethereum.ipc"
)

{:ok, response} = Transportable.call(transport, request)

Configuration

Required options:

  • :path - The Unix domain socket path (e.g., "/tmp/ethereum.ipc")

Optional options:

  • :timeout - Request timeout in milliseconds (defaults to 30000)
  • :socket_opts - TCP socket options (defaults to [:binary, active: false, reuseaddr: true])
  • :pool_size - Number of connections in the pool (defaults to 10)
  • :pool_lazy_workers - Whether to create workers lazily (defaults to true)
  • :pool_worker_idle_timeout - Worker idle timeout (defaults to nil)
  • :pool_max_idle_pings - Maximum idle pings before worker termination (defaults to -1)

Connection Pooling

The IPC transport uses NimblePool to manage a pool of Unix domain socket connections. This provides several benefits:

  • Efficient resource utilization
  • Automatic connection lifecycle management
  • Configurable pool size for different workloads
  • Connection reuse for better performance

Error Handling

The transport handles several error cases:

  • Invalid socket path format
  • Missing required options
  • Connection failures
  • Socket communication errors
  • Pool exhaustion

See Exth.Transport.Transportable for protocol details.

Summary

Types

t()

IPC transport configuration

Types

t()

@type t() :: %Exth.Transport.Ipc{
  path: String.t(),
  pool: struct(),
  socket_opts: list(),
  timeout: non_neg_integer()
}

IPC transport configuration

Functions

call(transport, request)

@spec call(t(), String.t()) :: {:ok, String.t()} | {:error, term()}

new(opts)

@spec new(keyword()) :: t()