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
Class Method Summary collapse
-
.abstract?(path) ⇒ Boolean
True if abstract namespace path.
-
.apply_buffer_sizes(sock, options) ⇒ Object
Applies SO_SNDBUF / SO_RCVBUF to
sockfrom the socket’s Options. -
.dialer(endpoint, engine) ⇒ Dialer
Creates an IPC dialer for an endpoint.
-
.listener(endpoint, engine) ⇒ Listener
Creates a bound IPC listener.
-
.parse_path(endpoint) ⇒ Object
Extracts path from “ipc://path”.
-
.to_socket_path(path) ⇒ Object
Converts @ prefix to 0 for abstract namespace.
Class Method Details
.abstract?(path) ⇒ Boolean
Returns 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).
54 55 56 57 58 59 60 61 62 |
# File 'lib/omq/transport/ipc.rb', line 54 def apply_buffer_sizes(sock, ) if .sndbuf sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDBUF, .sndbuf) end if .rcvbuf sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_RCVBUF, .rcvbuf) end end |
.dialer(endpoint, engine) ⇒ Dialer
Creates an IPC dialer for an endpoint.
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.
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 |