Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,16 @@ impl<'a> PollItem<'a> {
pub fn is_error(&self) -> bool {
(self.revents & POLLERR.bits()) != 0
}

/// Returns true if the polled socket is the given 0MQ socket.
pub fn has_socket(&self, socket: &Socket) -> bool {
self.socket == socket.sock
}

/// Returns true if the polled socket is the given file descriptor.
pub fn has_fd(&self, fd: RawFd) -> bool {
self.socket.is_null() && self.fd == fd
}
}

/// Poll for events on multiple sockets.
Expand Down
1 change: 1 addition & 0 deletions tests/poll/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn test_pipe_poll() {
pipe_writer(pipe_write);
});
let pipe_item = zmq::PollItem::from_fd(pipe_read, zmq::POLLIN);
assert!(pipe_item.has_fd(pipe_read));

let mut poll_items = [pipe_item];
assert_eq!(zmq::poll(&mut poll_items, 1000).unwrap(), 1);
Expand Down
5 changes: 5 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ test!(test_polling, {
let mut poll_items = vec![receiver.as_poll_item(POLLIN)];
assert_eq!(poll(&mut poll_items, 1000).unwrap(), 1);
assert_eq!(poll_items[0].get_revents(), POLLIN);
assert!(poll_items[0].is_readable());
assert!(!poll_items[0].is_writable());
assert!(!poll_items[0].is_error());
assert!(poll_items[0].has_socket(&receiver));
assert!(!poll_items[0].has_fd(0));
});

test!(test_raw_roundtrip, {
Expand Down