poll.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_POLL_HPP_INCLUDED__
4 #define __ZMQ_POLL_HPP_INCLUDED__
5 
6 // poller.hpp decides which polling mechanism to use.
7 #include "poller.hpp"
8 #if defined ZMQ_IOTHREAD_POLLER_USE_POLL
9 
10 #if defined ZMQ_HAVE_WINDOWS
11 #error \
12  "poll is broken on Windows for the purpose of the I/O thread poller, use select instead; "\
13  "see https://github.com/zeromq/libzmq/issues/3107"
14 #endif
15 
16 #include <poll.h>
17 #include <stddef.h>
18 #include <vector>
19 
20 #include "ctx.hpp"
21 #include "fd.hpp"
22 #include "thread.hpp"
23 #include "poller_base.hpp"
24 
25 namespace zmq
26 {
27 struct i_poll_events;
28 
29 // Implements socket polling mechanism using the POSIX.1-2001
30 // poll() system call.
31 
32 class poll_t ZMQ_FINAL : public worker_poller_base_t
33 {
34  public:
35  typedef fd_t handle_t;
36 
37  poll_t (const thread_ctx_t &ctx_);
38  ~poll_t ();
39 
40  // "poller" concept.
41  // These methods may only be called from an event callback; add_fd may also be called before start.
42  handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_);
43  void rm_fd (handle_t handle_);
44  void set_pollin (handle_t handle_);
45  void reset_pollin (handle_t handle_);
46  void set_pollout (handle_t handle_);
47  void reset_pollout (handle_t handle_);
48  void stop ();
49 
50  static int max_fds ();
51 
52  private:
53  // Main event loop.
54  void loop () ZMQ_FINAL;
55 
56  void cleanup_retired ();
57 
58  struct fd_entry_t
59  {
60  fd_t index;
61  zmq::i_poll_events *events;
62  };
63 
64  // This table stores data for registered descriptors.
65  typedef std::vector<fd_entry_t> fd_table_t;
66  fd_table_t fd_table;
67 
68  // Pollset to pass to the poll function.
69  typedef std::vector<pollfd> pollset_t;
70  pollset_t pollset;
71 
72  // If true, there's at least one retired event source.
73  bool retired;
74 
76 };
77 
78 typedef poll_t poller_t;
79 }
80 
81 #endif
82 
83 #endif
zmq::i_poll_events
Definition: i_poll_events.hpp:13
ctx.hpp
zmq
Definition: zmq.hpp:229
poller.hpp
ZMQ_NON_COPYABLE_NOR_MOVABLE
#define ZMQ_NON_COPYABLE_NOR_MOVABLE(classname)
Definition: macros.hpp:58
thread.hpp
fd.hpp
fd_t
zmq_fd_t fd_t
Definition: libzmq/tests/testutil.hpp:98
ZMQ_FINAL
Definition: unittest_ip_resolver.cpp:26
index
GLuint index
Definition: glcorearb.h:3055
poller_base.hpp


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:57