pollset.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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_POLLSET_HPP_INCLUDED__
  25. #define __ZMQ_POLLSET_HPP_INCLUDED__
  26. // poller.hpp decides which polling mechanism to use.
  27. #include "poller.hpp"
  28. #if defined ZMQ_IOTHREAD_POLLER_USE_POLLSET
  29. #include <sys/poll.h>
  30. #include <sys/pollset.h>
  31. #include <vector>
  32. #include "ctx.hpp"
  33. #include "fd.hpp"
  34. #include "thread.hpp"
  35. #include "poller_base.hpp"
  36. namespace zmq
  37. {
  38. struct i_poll_events;
  39. // This class implements socket polling mechanism using the AIX-specific
  40. // pollset mechanism.
  41. class pollset_t ZMQ_FINAL : public poller_base_t
  42. {
  43. public:
  44. typedef void *handle_t;
  45. pollset_t (const thread_ctx_t &ctx_);
  46. ~pollset_t () ZMQ_FINAL;
  47. // "poller" concept.
  48. handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_);
  49. void rm_fd (handle_t handle_);
  50. void set_pollin (handle_t handle_);
  51. void reset_pollin (handle_t handle_);
  52. void set_pollout (handle_t handle_);
  53. void reset_pollout (handle_t handle_);
  54. void start ();
  55. void stop ();
  56. static int max_fds ();
  57. private:
  58. // Main worker thread routine.
  59. static void worker_routine (void *arg_);
  60. // Main event loop.
  61. void loop () ZMQ_FINAL;
  62. // Reference to ZMQ context.
  63. const thread_ctx_t &ctx;
  64. // Main pollset file descriptor
  65. ::pollset_t pollset_fd;
  66. struct poll_entry_t
  67. {
  68. fd_t fd;
  69. bool flag_pollin;
  70. bool flag_pollout;
  71. zmq::i_poll_events *events;
  72. };
  73. // List of retired event sources.
  74. typedef std::vector<poll_entry_t *> retired_t;
  75. retired_t retired;
  76. // This table stores data for registered descriptors.
  77. typedef std::vector<poll_entry_t *> fd_table_t;
  78. fd_table_t fd_table;
  79. // If true, thread is in the process of shutting down.
  80. bool stopping;
  81. // Handle of the physical thread doing the I/O work.
  82. thread_t worker;
  83. ZMQ_NON_COPYABLE_NOR_MOVABLE (pollset_t)
  84. };
  85. typedef pollset_t poller_t;
  86. }
  87. #endif
  88. #endif