kqueue.hpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #ifndef __ZMQ_KQUEUE_HPP_INCLUDED__
4 #define __ZMQ_KQUEUE_HPP_INCLUDED__
5 
6 // poller.hpp decides which polling mechanism to use.
7 #include "poller.hpp"
8 #if defined ZMQ_IOTHREAD_POLLER_USE_KQUEUE
9 
10 #include <vector>
11 #include <unistd.h>
12 
13 #include "ctx.hpp"
14 #include "fd.hpp"
15 #include "thread.hpp"
16 #include "poller_base.hpp"
17 
18 namespace zmq
19 {
20 struct i_poll_events;
21 
22 // Implements socket polling mechanism using the BSD-specific
23 // kqueue interface.
24 
25 class kqueue_t ZMQ_FINAL : public worker_poller_base_t
26 {
27  public:
28  typedef void *handle_t;
29 
30  kqueue_t (const thread_ctx_t &ctx_);
31  ~kqueue_t () ZMQ_FINAL;
32 
33  // "poller" concept.
34  handle_t add_fd (fd_t fd_, zmq::i_poll_events *events_);
35  void rm_fd (handle_t handle_);
36  void set_pollin (handle_t handle_);
37  void reset_pollin (handle_t handle_);
38  void set_pollout (handle_t handle_);
39  void reset_pollout (handle_t handle_);
40  void stop ();
41 
42  static int max_fds ();
43 
44  private:
45  // Main event loop.
46  void loop () ZMQ_FINAL;
47 
48  // File descriptor referring to the kernel event queue.
49  fd_t kqueue_fd;
50 
51  // Adds the event to the kqueue.
52  void kevent_add (fd_t fd_, short filter_, void *udata_);
53 
54  // Deletes the event from the kqueue.
55  void kevent_delete (fd_t fd_, short filter_);
56 
57  struct poll_entry_t
58  {
59  fd_t fd;
60  bool flag_pollin;
61  bool flag_pollout;
62  zmq::i_poll_events *reactor;
63  };
64 
65  // List of retired event sources.
66  typedef std::vector<poll_entry_t *> retired_t;
67  retired_t retired;
68 
70 
71 #ifdef HAVE_FORK
72  // the process that created this context. Used to detect forking.
73  pid_t pid;
74 #endif
75 };
76 
77 typedef kqueue_t poller_t;
78 }
79 
80 #endif
81 
82 #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
poller_base.hpp


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