jean-airoldie / libzmq-rs

A strict subset of ØMQ with an ergonomic API.
https://jean-airoldie.github.io/libzmq-rs/
Apache License 2.0
58 stars 4 forks source link

WIP: Add socket events #122

Closed jean-airoldie closed 5 years ago

jean-airoldie commented 5 years ago

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