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

Socket notifications #123

Open jean-airoldie opened 5 years ago

jean-airoldie commented 5 years ago

By leveraging the zmq_socket_monitor API, allow sockets to receive events that are normally discarted by libzmq. Allow the user to configure what events should be received or discarded.

See #122 for more information.

jean-airoldie commented 5 years ago

This would be a way better approach https://github.com/zeromq/libzmq/issues/3658.

This would essentially allow us to configure a socket to receive notifications in Msg based on a set of interests. The interests would be something like a bitflag that would tell zmq what events we are interested it. By default, sockets would have no interests, aka. stateless.

Here are the possible approaches for passing events to the user:

As a Msg

let msg = client.recv_msg()?;
if msg.is_notif() {
  match msg.notif() {
    Notif::Disconnected => ...,
    _ => ...,
  }
} else {
  // proceed like normal.
}

Pros

As the content of a Msg

  let msg = client.recv_msg()?;
  match msg.content() {
    Content::Bytes(bytes) => ...,
    Content::Notif(notif) => ...,
  }

Pros

As an error

  match client.recv_msg() {
    Ok(msg) => ...,
    Err(err) => match err.kind() {
      ErrorKind::Notif(notif) => ...,
      _ => ...,
    }
  }

Pros

So I think that the notification as an error approach is the best one. Even if there is some metadata contained within the message, we can retrieve it and give it back to the client.