class Context
A bound context for receiving messages.
Definitions
def initialize(path)
Initialize the context with the given path.
Signature
-
parameter
path
String
The path to the UNIX socket.
Implementation
def initialize(path)
@path = path
@bound = Addrinfo.unix(@path, ::Socket::SOCK_DGRAM).bind
@state = {}
end
def close
Close the bound context.
Implementation
def close
@bound.close
File.unlink(@path)
end
def receive
Receive a message from the bound context.
Signature
-
returns
Hash
The parsed message.
Implementation
def receive
while true
data, _address, _flags, *_controls = @bound.recvmsg(MAXIMUM_MESSAGE_SIZE)
message = Server.load(data)
if block_given?
yield message
else
return message
end
end
end