Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socketevent bitflags macro #353

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tosti007
Copy link

This PR replaces the SocketEvent struct with a macro call to the (existing) bitflags crate. Additionally, monitor's event argument now takes a SocketEvent rather than the previous raw integer.

The docstrings come from the docs and the header file.

Notably, I removed the SocketEvent::ALL option in favor of SocketEvent::all(), due to two reasons: removing the bitflags all function is not possible and by using the all function, all rust-defined events are passed only, rather than 0xFFFF. The original behaviour is still possible by using: SocketEvent::from_bits_unchecked(0xFFFF).

An example of the change in this PR (with type annotation), before:

let events: u32 = SocketEvent::CONNECTED.to_raw()
        | SocketEvent::CONNECT_DELAYED.to_raw()
        | SocketEvent::CONNECT_RETRIED.to_raw()
        | SocketEvent::DISCONNECTED.to_raw();
socket.monitor(&endpoint, events as i32)?;

After:

let events: SocketEvent = SocketEvent::CONNECTED
        | SocketEvent::CONNECT_DELAYED
        | SocketEvent::CONNECT_RETRIED
        | SocketEvent::DISCONNECTED;
socket.monitor(&endpoint, events)?;

src/lib.rs Outdated Show resolved Hide resolved
HANDSHAKE_SUCCEEDED = zmq_sys::ZMQ_EVENT_HANDSHAKE_SUCCEEDED as isize,
HANDSHAKE_FAILED_PROTOCOL = zmq_sys::ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL as isize,
HANDSHAKE_FAILED_AUTH = zmq_sys::ZMQ_EVENT_HANDSHAKE_FAILED_AUTH as isize,
ALL = zmq_sys::ZMQ_EVENT_ALL as isize,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed prior, all() returns a union of all flags, which for this pair of constants seems to result in (1<<15) - 1 whereas ZMQ_EVENT_ALL is defined as (1 << 16) - 1 - the highest bit 1<<15 isn't used by a constant yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the suggestion is to probably keep this around - which automatically makes ::all() return the same value as ALL even if there's one bit that appears to be "reserved".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants