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: Listener

Class Method Summary collapse

Class Method Details

.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)


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

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

.bind(endpoint, engine) ⇒ Listener

Binds an IPC server.

Parameters:

  • endpoint (String)

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

  • engine (Engine)

Returns:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/omq/transport/ipc.rb', line 21

def bind(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

.connect(endpoint, engine) ⇒ void

This method returns an undefined value.

Connects to an IPC endpoint.

Parameters:

  • endpoint (String)
  • engine (Engine)


40
41
42
43
44
45
46
# File 'lib/omq/transport/ipc.rb', line 40

def connect(endpoint, engine)
  path = parse_path(endpoint)
  sock_path = to_socket_path(path)
  sock = UNIXSocket.new(sock_path)
  apply_buffer_sizes(sock, engine.options)
  engine.handle_connected(IO::Stream::Buffered.wrap(sock), endpoint: endpoint)
end