File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -1055,6 +1055,16 @@ impl<'a> PollItem<'a> {
10551055 pub fn is_error ( & self ) -> bool {
10561056 ( self . revents & POLLERR . bits ( ) ) != 0
10571057 }
1058+
1059+ /// Returns true if the polled socket is the given 0MQ socket.
1060+ pub fn has_socket ( & self , socket : & Socket ) -> bool {
1061+ self . socket == socket. sock
1062+ }
1063+
1064+ /// Returns true if the polled socket is the given file descriptor.
1065+ pub fn has_fd ( & self , fd : RawFd ) -> bool {
1066+ self . socket . is_null ( ) && self . fd == fd
1067+ }
10581068}
10591069
10601070/// Poll for events on multiple sockets.
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ fn test_pipe_poll() {
1212 pipe_writer ( pipe_write) ;
1313 } ) ;
1414 let pipe_item = zmq:: PollItem :: from_fd ( pipe_read, zmq:: POLLIN ) ;
15+ assert ! ( pipe_item. has_fd( pipe_read) ) ;
1516
1617 let mut poll_items = [ pipe_item] ;
1718 assert_eq ! ( zmq:: poll( & mut poll_items, 1000 ) . unwrap( ) , 1 ) ;
Original file line number Diff line number Diff line change @@ -98,6 +98,11 @@ test!(test_polling, {
9898 let mut poll_items = vec![ receiver. as_poll_item( POLLIN ) ] ;
9999 assert_eq!( poll( & mut poll_items, 1000 ) . unwrap( ) , 1 ) ;
100100 assert_eq!( poll_items[ 0 ] . get_revents( ) , POLLIN ) ;
101+ assert!( poll_items[ 0 ] . is_readable( ) ) ;
102+ assert!( !poll_items[ 0 ] . is_writable( ) ) ;
103+ assert!( !poll_items[ 0 ] . is_error( ) ) ;
104+ assert!( poll_items[ 0 ] . has_socket( & receiver) ) ;
105+ assert!( !poll_items[ 0 ] . has_fd( 0 ) ) ;
101106} ) ;
102107
103108test ! ( test_raw_roundtrip, {
You can’t perform that action at this time.
0 commit comments