1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843
//! Asynchronous polling mechanim. //! //! See the [`Poller`] documentation to get started. //! //! [`Poller`]: struct.Poller.html use crate::{ core::{GetRawSocket, Period, RawSocket}, error::{msg_from_errno, Error, ErrorKind}, old::OldSocket, socket::*, }; use libzmq_sys as sys; use sys::errno; use bitflags::bitflags; use std::os::{ raw::{c_long, c_short, c_void}, unix::io::{AsRawFd, RawFd}, }; bitflags! { /// A bitflag used to specifies the condition for triggering an [`Event`] in the /// [`Poller`]. /// /// # Example /// ``` /// use libzmq::poll::*; /// /// // This specifies to the poller to trigger an event if `Pollable` is /// // readable and/or writable. /// let either = READABLE | WRITABLE; /// ``` /// /// [`Event`]: struct.Event.html /// [`Poller`]: struct.Poller.html pub struct Trigger: c_short { /// Never trigger. const EMPTY = 0i16; /// Trigger an `Event` on read readiness. /// /// For a `libzmq` socket this means that at least one message can be /// received without blocking. For a standard socket, this means /// that at least one byte of data may be read from the fd without /// blocking const READABLE = sys::ZMQ_POLLIN as c_short; /// Trigger an `Event` on write readiness. /// /// For a `libzmq` socket this means that at least one message can /// be sent without blocking. For a standard socket, this means /// that at lesat one bye of data may be written to the fd without /// blocking. const WRITABLE = sys::ZMQ_POLLOUT as c_short; } } /// Never trigger an `Event` while polling. pub const EMPTY: Trigger = Trigger::EMPTY; /// Trigger an `Event` on read readiness. /// /// For a `libzmq` socket this means that at least one message can be /// received without blocking. For a standard socket, this means /// that at least one byte of data may be read from the fd without /// blocking pub const READABLE: Trigger = Trigger::READABLE; /// Trigger an `Event` on write readiness. /// /// For a `libzmq` socket this means that at least one message can /// be sent without blocking. For a standard socket, this means /// that at lesat one bye of data may be written to the fd without /// blocking. pub const WRITABLE: Trigger = Trigger::WRITABLE; bitflags! { struct Cause: c_short { const READABLE = sys::ZMQ_POLLIN as c_short; const WRITABLE = sys::ZMQ_POLLOUT as c_short; const ERROR = sys::ZMQ_POLLERR as c_short; const PRIORITY = sys::ZMQ_POLLPRI as c_short; } } /// An alias to a [`Pollable`] element. /// /// [`Pollable`]: enum.Pollable.html #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct PollId(pub usize); impl From<usize> for PollId { fn from(val: usize) -> PollId { PollId(val) } } impl From<PollId> for usize { fn from(val: PollId) -> usize { val.0 } } /// The types that can be polled by the [`Poller`]. /// /// # Example /// ``` /// # fn main() -> Result<(), anyhow::Error> { /// use libzmq::{Server, poll::*}; /// use std::net::TcpListener; /// /// let mut poller = Poller::new(); /// /// // The poller can poll sockets... /// let server = Server::new()?; /// poller.add(&server, PollId(0), READABLE)?; /// /// // ...as well as any type that implements `AsRawFd`. /// let tcp_listener = TcpListener::bind("127.0.0.1:0")?; /// poller.add(&tcp_listener, PollId(1), READABLE | WRITABLE)?; /// # /// # Ok(()) /// # } /// ``` /// /// [`Poller`]: struct.Poller.html#method.add pub enum Pollable<'a> { /// A `Socket` type. Socket(&'a RawSocket), /// A file descriptor. Fd(RawFd), } impl<'a, T> From<&'a T> for Pollable<'a> where T: AsRawFd, { fn from(entity: &'a T) -> Self { Pollable::Fd(entity.as_raw_fd()) } } impl<'a> From<&'a Client> for Pollable<'a> { fn from(client: &'a Client) -> Self { Pollable::Socket(client.raw_socket()) } } impl<'a> From<&'a Server> for Pollable<'a> { fn from(server: &'a Server) -> Self { Pollable::Socket(server.raw_socket()) } } impl<'a> From<&'a Radio> for Pollable<'a> { fn from(radio: &'a Radio) -> Self { Pollable::Socket(radio.raw_socket()) } } impl<'a> From<&'a Dish> for Pollable<'a> { fn from(dish: &'a Dish) -> Self { Pollable::Socket(dish.raw_socket()) } } impl<'a> From<&'a Gather> for Pollable<'a> { fn from(gather: &'a Gather) -> Self { Pollable::Socket(gather.raw_socket()) } } impl<'a> From<&'a Scatter> for Pollable<'a> { fn from(scatter: &'a Scatter) -> Self { Pollable::Socket(scatter.raw_socket()) } } #[doc(hidden)] impl<'a> From<&'a OldSocket> for Pollable<'a> { fn from(old: &'a OldSocket) -> Self { Pollable::Socket(old.raw_socket()) } } /// An `Iterator` over references to [`Event`]. /// /// Note that every event is guaranteed to be non-[`EMPTY`]. /// /// [`EMPTY`]: constant.EMPTY.html /// [`Event`]: struct.Event.html #[derive(Clone, Debug)] pub struct Iter<'a> { inner: &'a Events, pos: usize, } impl<'a> Iterator for Iter<'a> { type Item = Event; #[inline] fn next(&mut self) -> Option<Self::Item> { let raw = self.inner.inner.get(self.pos); self.pos += 1; if let Some(event) = raw { // Skip empty events. if event.events == 0 { self.next() } else { let user_data = event.user_data as *mut usize as usize; Some(Event { id: PollId(user_data), cause: Cause::from_bits(event.events).unwrap(), }) } } else { None } } #[inline] fn size_hint(&self) -> (usize, Option<usize>) { let len = self.inner.inner.len(); (len, Some(len)) } } /// An `Iterator` over a set of [`Event`]. /// /// Note that every event is guaranteed to be non-[`EMPTY`]. /// /// [`EMPTY`]: constant.EMPTY.html /// [`Event`]: struct.Event.html #[derive(Debug)] pub struct IntoIter { inner: Events, pos: usize, } impl Iterator for IntoIter { type Item = Event; #[inline] fn next(&mut self) -> Option<Self::Item> { let raw = self.inner.inner.get(self.pos); self.pos += 1; raw.map(|raw| { let user_data = raw.user_data as *mut usize as usize; Event { id: PollId(user_data), cause: Cause::from_bits(raw.events).unwrap(), } }) } #[inline] fn size_hint(&self) -> (usize, Option<usize>) { let len = self.inner.inner.len(); (len, Some(len)) } } /// An event detected by a poller. #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct Event { cause: Cause, id: PollId, } impl Event { /// Indicates read readiness. pub fn is_readable(&self) -> bool { self.cause.contains(Cause::READABLE) } /// Indicates write readiness. pub fn is_writable(&self) -> bool { self.cause.contains(Cause::WRITABLE) } /// Indicates that an error was received. /// /// This event can only occur if a `RawFd` is polled. pub fn is_error(&self) -> bool { self.cause.contains(Cause::ERROR) } /// Indicates that there is urgent data to be read. /// /// This event can only occur if a `RawFd` is polled. pub fn is_priority(&self) -> bool { self.cause.contains(Cause::PRIORITY) } /// Returns the [`PollId`] associated with the event. /// /// [`PollId`]: struct.PollId.html pub fn id(&self) -> PollId { self.id } } /// A vector of [`Event`] detected while polling. /// /// [`Event`]: struct.Event.html #[derive(Default, Clone, Eq, PartialEq, Hash, Debug)] pub struct Events { inner: Vec<sys::zmq_poller_event_t>, } impl Events { /// Creates a new empty event vector. pub fn new() -> Self { Self::default() } /// Create a new event vector with the specified capacity. pub fn with_capacity(capacity: usize) -> Self { Self { inner: Vec::with_capacity(capacity), } } /// Returns the capacity of the event vector. pub fn capacity(&self) -> usize { self.inner.capacity() } /// Returns `true` is the event vector contains no events. pub fn is_empty(&self) -> bool { self.inner.is_empty() } /// Returns an iterator over the `Event` in the event vector. pub fn iter(&self) -> Iter { Iter { inner: &self, pos: 0, } } /// Empties the event vector. pub fn clear(&mut self) { self.inner.clear(); } } impl<'a> IntoIterator for &'a Events { type Item = Event; type IntoIter = Iter<'a>; fn into_iter(self) -> Self::IntoIter { self.iter() } } impl IntoIterator for Events { type Item = Event; type IntoIter = IntoIter; fn into_iter(self) -> Self::IntoIter { IntoIter { inner: self, pos: 0, } } } /// A mechanism for input/output events multiplexing in a level-triggered fashion. /// /// The poller is used to asynchronously detect events of a set of monitored /// [`Pollable`] elements. These elements must be registered for monitoring by /// [`adding`] them to the `Poller`. /// /// # Example /// ``` /// # fn main() -> Result<(), anyhow::Error> { /// use libzmq::{prelude::*, *, poll::*}; /// /// // We initialize our sockets and connect them to each other. /// let addr: TcpAddr = "127.0.0.1:*".try_into()?; /// /// let server = Server::new()?; /// server.bind(addr)?; /// /// let bound = server.last_endpoint()?; /// /// let client = Client::new()?; /// client.connect(&bound)?; /// /// // We create our poller instance. /// let mut poller = Poller::new(); /// poller.add(&server, PollId(0), READABLE)?; /// poller.add(&client, PollId(1), READABLE)?; /// /// // Initialize the client. /// client.send("ping")?; /// /// let mut events = Events::new(); /// /// // Now the client and each server will send messages back and forth. /// for _ in 0..100 { /// // Wait indefinitely until at least one event is detected. /// poller.poll(&mut events, Period::Infinite)?; /// // Iterate over the detected events. Note that, since the events are /// // guaranteed to be non-empty, we don't need to protect against spurious /// // wakeups. /// for event in &events { /// assert!(event.is_readable()); /// match event.id() { /// // The server is ready to receive an incoming message. /// PollId(0) => { /// let msg = server.recv_msg()?; /// assert_eq!("ping", msg.to_str()?); /// server.send(msg)?; /// } /// // One of the clients is ready to receive an incoming message. /// PollId(1) => { /// let msg = client.recv_msg()?; /// assert_eq!("ping", msg.to_str()?); /// client.send(msg)?; /// } /// _ => unreachable!(), /// } /// } /// } /// # /// # Ok(()) /// # } /// ``` /// /// [`Pollable`]: enum.Pollable.html /// [`adding`]: #method.add #[derive(Eq, PartialEq, Debug)] pub struct Poller { poller: *mut c_void, count: usize, } impl Poller { /// Create a new empty poller. pub fn new() -> Self { Self::default() } /// Add a [`Pollable`] element for monitoring by the poller with the /// specified [`Trigger`] condition. /// /// # Returned Errors /// * [`InvalidInput`] (added socket twice or invalid fd) /// /// # Example /// ``` /// # fn main() -> Result<(), anyhow::Error> { /// use libzmq::{Server, poll::*, ErrorKind}; /// /// let server = Server::new()?; /// /// let mut poller = Poller::new(); /// /// poller.add(&server, PollId(0), EMPTY)?; /// let err = poller.add(&server, PollId(1), EMPTY).unwrap_err(); /// /// match err.kind() { /// ErrorKind::InvalidInput { .. } => (), /// _ => panic!("unexpected error"), /// } /// # /// # Ok(()) /// # } /// ``` /// /// [`InvalidInput`]: ../enum.ErrorKind.html#variant.InvalidInput /// [`Pollable`]: enum.Pollable.html /// [`Trigger`]: struct.Trigger.html pub fn add<'a, P>( &mut self, pollable: P, id: PollId, trigger: Trigger, ) -> Result<(), Error> where P: Into<Pollable<'a>>, { match pollable.into() { Pollable::Socket(raw_socket) => { self.add_raw_socket(raw_socket, id, trigger) } Pollable::Fd(fd) => self.add_fd(fd, id, trigger), } } fn add_fd( &mut self, fd: RawFd, id: PollId, trigger: Trigger, ) -> Result<(), Error> { let user_data: usize = id.into(); let user_data = user_data as *mut usize as *mut c_void; let rc = unsafe { sys::zmq_poller_add_fd(self.poller, fd, user_data, trigger.bits()) }; if rc == -1 { let errno = unsafe { sys::zmq_errno() }; let err = match errno { errno::EINVAL => { Error::new(ErrorKind::InvalidInput("cannot add fd twice")) } errno::EBADF => Error::new(ErrorKind::InvalidInput( "specified fd was the retired fd", )), _ => panic!(msg_from_errno(errno)), }; Err(err) } else { self.count += 1; Ok(()) } } fn add_raw_socket( &mut self, raw_socket: &RawSocket, id: PollId, trigger: Trigger, ) -> Result<(), Error> { let socket_mut_ptr = raw_socket.as_mut_ptr(); let user_data: usize = id.into(); let user_data = user_data as *mut usize as *mut c_void; let rc = unsafe { sys::zmq_poller_add( self.poller, socket_mut_ptr, user_data, trigger.bits(), ) }; if rc == -1 { let errno = unsafe { sys::zmq_errno() }; let err = match errno { errno::EINVAL => Error::new(ErrorKind::InvalidInput( "cannot add socket twice", )), errno::ENOTSOCK => panic!("invalid socket"), _ => panic!(msg_from_errno(errno)), }; Err(err) } else { self.count += 1; Ok(()) } } /// Remove a [`Pollable`] element from monitoring by the poller. /// /// # Returned Errors /// * [`InvalidInput`] (element not present or invalid fd) /// /// # Example /// ``` /// # fn main() -> Result<(), anyhow::Error> { /// use libzmq::{Server, poll::*, ErrorKind}; /// /// let server = Server::new()?; /// let mut poller = Poller::new(); /// /// poller.add(&server, PollId(0), EMPTY)?; /// poller.remove(&server)?; /// /// let err = poller.remove(&server).unwrap_err(); /// match err.kind() { /// ErrorKind::InvalidInput { .. } => (), // cannot remove socket twice. /// _ => panic!("unexpected error"), /// } /// # /// # Ok(()) /// # } /// ``` /// /// [`InvalidInput`]: ../enum.ErrorKind.html#variant.InvalidInput /// [`Pollable`]: enum.Pollable.html pub fn remove<'a, P>(&mut self, pollable: P) -> Result<(), Error> where P: Into<Pollable<'a>>, { match pollable.into() { Pollable::Socket(raw_socket) => self.remove_raw_socket(raw_socket), Pollable::Fd(fd) => self.remove_fd(fd), } } fn remove_fd(&mut self, fd: RawFd) -> Result<(), Error> { let rc = unsafe { sys::zmq_poller_remove_fd(self.poller, fd) }; if rc == -1 { let errno = unsafe { sys::zmq_errno() }; let err = match errno { errno::EINVAL => Error::new(ErrorKind::InvalidInput( "cannot remove absent fd", )), errno::EBADF => Error::new(ErrorKind::InvalidInput( "specified fd was the retired fd", )), _ => panic!(msg_from_errno(errno)), }; Err(err) } else { self.count -= 1; Ok(()) } } fn remove_raw_socket( &mut self, raw_socket: &RawSocket, ) -> Result<(), Error> { let socket_mut_ptr = raw_socket.as_mut_ptr(); let rc = unsafe { sys::zmq_poller_remove(self.poller, socket_mut_ptr) }; if rc == -1 { let errno = unsafe { sys::zmq_errno() }; let err = match errno { errno::ENOTSOCK => panic!("invalid socket"), errno::EINVAL => Error::new(ErrorKind::InvalidInput( "cannot remove absent socket", )), _ => panic!(msg_from_errno(errno)), }; Err(err) } else { self.count -= 1; Ok(()) } } /// Modify the [`Trigger`] confition for the specified [`Pollable`] element /// monitored by the poller. /// /// # Returned Errors /// * [`InvalidInput`] (element not present or invalid fd) /// /// [`InvalidInput`]: ../enum.ErrorKind.html#variant.InvalidInput /// [`Pollable`]: enum.Pollable.html /// [`Trigger`]: struct.Trigger.html pub fn modify<'a, P>( &mut self, pollable: P, trigger: Trigger, ) -> Result<(), Error> where P: Into<Pollable<'a>>, { match pollable.into() { Pollable::Socket(raw_socket) => { self.modify_raw_socket(raw_socket, trigger) } Pollable::Fd(fd) => self.modify_fd(fd, trigger), } } fn modify_fd(&mut self, fd: RawFd, trigger: Trigger) -> Result<(), Error> { let rc = unsafe { sys::zmq_poller_modify_fd(self.poller, fd, trigger.bits()) }; if rc == -1 { let errno = unsafe { sys::zmq_errno() }; let err = match errno { errno::EINVAL => Error::new(ErrorKind::InvalidInput( "cannot modify absent fd", )), errno::EBADF => Error::new(ErrorKind::InvalidInput( "specified fd is the retired fd", )), _ => panic!(msg_from_errno(errno)), }; Err(err) } else { Ok(()) } } fn modify_raw_socket( &mut self, raw_socket: &RawSocket, trigger: Trigger, ) -> Result<(), Error> { let socket_mut_ptr = raw_socket.as_mut_ptr(); let rc = unsafe { sys::zmq_poller_modify(self.poller, socket_mut_ptr, trigger.bits()) }; if rc == -1 { let errno = unsafe { sys::zmq_errno() }; let err = match errno { errno::EINVAL => Error::new(ErrorKind::InvalidInput( "cannot modify absent socket", )), errno::ENOTSOCK => panic!("invalid socket"), _ => panic!(msg_from_errno(errno)), }; Err(err) } else { Ok(()) } } fn wait(&mut self, events: &mut Events, timeout: i64) -> Result<(), Error> { events.clear(); for _i in 0..self.count { events.inner.push(sys::zmq_poller_event_t::default()); } let rc = unsafe { sys::zmq_poller_wait_all( self.poller, events.inner.as_mut_ptr(), events.inner.len() as i32, timeout as c_long, ) }; if rc == -1 { let errno = unsafe { sys::zmq_errno() }; let err = match errno { errno::EINVAL => panic!("invalid poller"), errno::ETERM => Error::new(ErrorKind::InvalidCtx), errno::EINTR => Error::new(ErrorKind::Interrupted), errno::EAGAIN => Error::new(ErrorKind::WouldBlock), _ => panic!(msg_from_errno(errno)), }; Err(err) } else { Ok(()) } } /// Check for events in the monitored elements, returning instantly. /// /// If no events occured, returns [`WouldBlock`]. Note that in this case, /// the `Events` would also be empty. /// /// # Returned Errors /// * [`WouldBlock`] /// * [`InvalidCtx`] (`Ctx` of a polled socket was terminated) /// * [`Interrupted`] /// /// [`Interrupted`]: ../enum.ErrorKind.html#variant.Interrupted /// [`InvalidCtx`]: ../enum.ErrorKind.html#variant.InvalidCtx /// [`WouldBlock`]: ../enum.ErrorKind.html#variant.Interrupted pub fn try_poll(&mut self, events: &mut Events) -> Result<(), Error> { self.wait(events, 0) } /// The poller will wait for events in the monitored elements, /// blocking until at least one event occurs, or the specified /// timeout `Period` expires. /// /// If the specified `Period` is infinite, the poller will block forever /// until an event occurs. /// /// # Returned Errors /// * [`WouldBlock`] (timeout expired) /// * [`InvalidCtx`] (`Ctx` of a polled socket was terminated) /// * [`Interrupted`] /// /// [`Interrupted`]: ../enum.ErrorKind.html#variant.Interrupted /// [`InvalidCtx`]: ../enum.ErrorKind.html#variant.InvalidCtx /// [`WouldBlock`]: ../enum.ErrorKind.html#variant.WouldBlock pub fn poll( &mut self, events: &mut Events, timeout: Period, ) -> Result<(), Error> { match timeout { Period::Finite(duration) => { let ms = duration.as_millis(); if ms > i64::max_value() as u128 { return Err(Error::new(ErrorKind::InvalidInput( "ms in timeout must be less than i64::MAX", ))); } self.wait(events, ms as i64) } Period::Infinite => self.wait(events, -1), } } } impl Default for Poller { fn default() -> Self { let poller = unsafe { sys::zmq_poller_new() }; if poller.is_null() { panic!(msg_from_errno(unsafe { sys::zmq_errno() })); } Self { poller, count: 0 } } } impl Drop for Poller { fn drop(&mut self) { let rc = unsafe { sys::zmq_poller_destroy(&mut self.poller) }; if rc != 0 { let errno = unsafe { sys::zmq_errno() }; match errno { errno::EFAULT => panic!("invalid poller"), _ => panic!(msg_from_errno(errno)), } } } } #[cfg(test)] mod test { use super::*; #[test] fn test_trigger() { assert_eq!(READABLE.bits(), sys::ZMQ_POLLIN as c_short); assert_eq!(WRITABLE.bits(), sys::ZMQ_POLLOUT as c_short); } }