Zeromq sockets are stateless, and this can be a bad thing. The aim of this PR is to leverage the zmq_socket_monitor API to enable statefull sockets that wakeup upon receiving specific events.
General design
The general concept is to allow the user to determine what events he is interested in. The specific events can be configured via a bitflag which will be used to filter events. So, by filtering all events, the user would have a stateless socket, which is what we have right now.
Example events
Peer timed out(peer handle) #heartbeat timeout
Peer timed us out(peer handle) #heartbeat timeout but from remote side
Peer disconnected(peer handle) #closing handshake
Reconnect Handshake failure(addr) #remote disconnected to change its certificate
Reconnect Timeout(addr)
Reconnected(peer handle)
Example usage
Drop a application session when a user timeouts or disconnects.
Publish a snapshot when a new subscriber arrives.
Wait for a connection to be establish.
Report a handshake failure.
General Implementation
We create a PAIR socket for each new socket, unless it is stateless, then we don't. When we send or recv from a socket, the socket first checks whether a event was received. If it was, it is returned as an error, with the ErrorKind::Event and the appropriate Event variant.
Zeromq sockets are stateless, and this can be a bad thing. The aim of this PR is to leverage the
zmq_socket_monitor
API to enable statefull sockets that wakeup upon receiving specific events.General design
The general concept is to allow the user to determine what events he is interested in. The specific events can be configured via a bitflag which will be used to filter events. So, by filtering all events, the user would have a stateless socket, which is what we have right now.
Example events
Example usage
General Implementation
We create a
PAIR
socket for each new socket, unless it is stateless, then we don't. When wesend
orrecv
from a socket, the socket first checks whether a event was received. If it was, it is returned as an error, with theErrorKind::Event
and the appropriateEvent
variant.