devpoll.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
  3. This file is part of libzmq, the ZeroMQ core engine in C++.
  4. libzmq is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU Lesser General Public License (LGPL) as published
  6. by the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. As a special exception, the Contributors give you permission to link
  9. this library with independent modules to produce an executable,
  10. regardless of the license terms of these independent modules, and to
  11. copy and distribute the resulting executable under terms of your choice,
  12. provided that you also meet, for each linked independent module, the
  13. terms and conditions of the license of that module. An independent
  14. module is a module which is not derived from or based on this library.
  15. If you modify this library, you must extend this exception to your
  16. version of the library.
  17. libzmq is distributed in the hope that it will be useful, but WITHOUT
  18. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  20. License for more details.
  21. You should have received a copy of the GNU Lesser General Public License
  22. along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. #ifndef __ZMQ_DEVPOLL_HPP_INCLUDED__
  25. #define __ZMQ_DEVPOLL_HPP_INCLUDED__
  26. // poller.hpp decides which polling mechanism to use.
  27. #include "poller.hpp"
  28. #if defined ZMQ_IOTHREAD_POLLER_USE_DEVPOLL
  29. #include <vector>
  30. #include "ctx.hpp"
  31. #include "fd.hpp"
  32. #include "thread.hpp"
  33. #include "poller_base.hpp"
  34. namespace zmq
  35. {
  36. struct i_poll_events;
  37. // Implements socket polling mechanism using the "/dev/poll" interface.
  38. class devpoll_t ZMQ_FINAL : public worker_poller_base_t
  39. {
  40. public:
  41. typedef fd_t handle_t;
  42. devpoll_t (const thread_ctx_t &ctx_);
  43. ~devpoll_t () ZMQ_FINAL;
  44. // "poller" concept.
  45. handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_);
  46. void rm_fd (handle_t handle_);
  47. void set_pollin (handle_t handle_);
  48. void reset_pollin (handle_t handle_);
  49. void set_pollout (handle_t handle_);
  50. void reset_pollout (handle_t handle_);
  51. void stop ();
  52. static int max_fds ();
  53. private:
  54. // Main event loop.
  55. void loop () ZMQ_FINAL;
  56. // File descriptor referring to "/dev/poll" pseudo-device.
  57. fd_t devpoll_fd;
  58. struct fd_entry_t
  59. {
  60. short events;
  61. zmq::i_poll_events *reactor;
  62. bool valid;
  63. bool accepted;
  64. };
  65. typedef std::vector<fd_entry_t> fd_table_t;
  66. fd_table_t fd_table;
  67. typedef std::vector<fd_t> pending_list_t;
  68. pending_list_t pending_list;
  69. // Pollset manipulation function.
  70. void devpoll_ctl (fd_t fd_, short events_);
  71. ZMQ_NON_COPYABLE_NOR_MOVABLE (devpoll_t)
  72. };
  73. typedef devpoll_t poller_t;
  74. }
  75. #endif
  76. #endif