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. -
.connection_class ⇒ Class
ZMTP connection class used for IPC-accepted/dialed peers.
-
.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.
94 95 96 |
# File 'lib/omq/transport/ipc.rb', line 94 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).
63 64 65 66 67 68 69 70 71 |
# File 'lib/omq/transport/ipc.rb', line 63 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 |
.connection_class ⇒ Class
ZMTP connection class used for IPC-accepted/dialed peers.
22 23 24 |
# File 'lib/omq/transport/ipc.rb', line 22 def connection_class Protocol::ZMTP::Connection end |
.dialer(endpoint, engine) ⇒ Dialer
Creates an IPC dialer for an endpoint.
52 53 54 |
# File 'lib/omq/transport/ipc.rb', line 52 def dialer(endpoint, engine, **) Dialer.new(endpoint, engine) end |
.listener(endpoint, engine) ⇒ Listener
Creates a bound IPC listener.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/omq/transport/ipc.rb', line 33 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”.
76 77 78 |
# File 'lib/omq/transport/ipc.rb', line 76 def parse_path(endpoint) endpoint.delete_prefix("ipc://") end |
.to_socket_path(path) ⇒ Object
Converts @ prefix to 0 for abstract namespace.
83 84 85 86 87 88 89 |
# File 'lib/omq/transport/ipc.rb', line 83 def to_socket_path(path) if abstract?(path) "\0#{path[1..]}" else path end end |