Module: OMQ::Transport::IPC

Defined in:
lib/omq/transport/ipc.rb

Overview

IPC transport using Unix domain sockets.

Supports both file-based paths and Linux abstract namespace (paths starting with @).

Defined Under Namespace

Classes: Dialer, Listener

Class Method Summary collapse

Class Method Details

.abstract?(path) ⇒ Boolean

Returns true if abstract namespace path.

Returns:

  • (Boolean)

    true if abstract namespace path



85
86
87
# File 'lib/omq/transport/ipc.rb', line 85

def abstract?(path)
  path.start_with?("@")
end

.apply_buffer_sizes(sock, options) ⇒ Object

Applies SO_SNDBUF / SO_RCVBUF to sock from the socket’s Options. No-op when both are nil (OS default).

Parameters:

  • sock (UNIXSocket, UNIXServer)
  • options (Options)


54
55
56
57
58
59
60
61
62
# File 'lib/omq/transport/ipc.rb', line 54

def apply_buffer_sizes(sock, options)
  if options.sndbuf
    sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, options.sndbuf)
  end

  if options.rcvbuf
    sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF, options.rcvbuf)
  end
end

.dialer(endpoint, engine) ⇒ Dialer

Creates an IPC dialer for an endpoint.

Parameters:

  • endpoint (String)
  • engine (Engine)

Returns:



43
44
45
# File 'lib/omq/transport/ipc.rb', line 43

def dialer(endpoint, engine, **)
  Dialer.new(endpoint, engine)
end

.listener(endpoint, engine) ⇒ Listener

Creates a bound IPC listener.

Parameters:

  • endpoint (String)

    e.g. “ipc:///tmp/my.sock” or “ipc://@abstract”

  • engine (Engine)

Returns:



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omq/transport/ipc.rb', line 24

def listener(endpoint, engine, **)
  path      = parse_path(endpoint)
  sock_path = to_socket_path(path)

  # Remove stale socket file for file-based paths
  File.delete(sock_path) if !abstract?(path) && File.exist?(sock_path)

  server = UNIXServer.new(sock_path)

  Listener.new(endpoint, server, path, engine)
end

.parse_path(endpoint) ⇒ Object

Extracts path from “ipc://path”.



67
68
69
# File 'lib/omq/transport/ipc.rb', line 67

def parse_path(endpoint)
  endpoint.delete_prefix("ipc://")
end

.to_socket_path(path) ⇒ Object

Converts @ prefix to 0 for abstract namespace.



74
75
76
77
78
79
80
# File 'lib/omq/transport/ipc.rb', line 74

def to_socket_path(path)
  if abstract?(path)
    "\0#{path[1..]}"
  else
    path
  end
end