Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / kqueue_reactor.hpp @ 2486

History | View | Annotate | Download (7.2 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/kqueue_reactor.hpp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
// Copyright (c) 2005 Stefan Arentz (stefan at soze dot com)
7 2486 sjacqu01
//
8 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
9 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 2486 sjacqu01
//
11 2486 sjacqu01
12 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_KQUEUE_REACTOR_HPP
13 2486 sjacqu01
#define BOOST_ASIO_DETAIL_KQUEUE_REACTOR_HPP
14 2486 sjacqu01
15 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 2486 sjacqu01
# pragma once
17 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 2486 sjacqu01
19 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
20 2486 sjacqu01
21 2486 sjacqu01
#if defined(BOOST_ASIO_HAS_KQUEUE)
22 2486 sjacqu01
23 2486 sjacqu01
#include <cstddef>
24 2486 sjacqu01
#include <sys/types.h>
25 2486 sjacqu01
#include <sys/event.h>
26 2486 sjacqu01
#include <sys/time.h>
27 2486 sjacqu01
#include <boost/asio/detail/limits.hpp>
28 2486 sjacqu01
#include <boost/asio/detail/mutex.hpp>
29 2486 sjacqu01
#include <boost/asio/detail/object_pool.hpp>
30 2486 sjacqu01
#include <boost/asio/detail/op_queue.hpp>
31 2486 sjacqu01
#include <boost/asio/detail/reactor_op.hpp>
32 2486 sjacqu01
#include <boost/asio/detail/select_interrupter.hpp>
33 2486 sjacqu01
#include <boost/asio/detail/socket_types.hpp>
34 2486 sjacqu01
#include <boost/asio/detail/timer_queue_base.hpp>
35 2486 sjacqu01
#include <boost/asio/detail/timer_queue_set.hpp>
36 2486 sjacqu01
#include <boost/asio/detail/wait_op.hpp>
37 2486 sjacqu01
#include <boost/asio/error.hpp>
38 2486 sjacqu01
#include <boost/asio/io_service.hpp>
39 2486 sjacqu01
40 2486 sjacqu01
// Older versions of Mac OS X may not define EV_OOBAND.
41 2486 sjacqu01
#if !defined(EV_OOBAND)
42 2486 sjacqu01
# define EV_OOBAND EV_FLAG1
43 2486 sjacqu01
#endif // !defined(EV_OOBAND)
44 2486 sjacqu01
45 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
46 2486 sjacqu01
47 2486 sjacqu01
namespace boost {
48 2486 sjacqu01
namespace asio {
49 2486 sjacqu01
namespace detail {
50 2486 sjacqu01
51 2486 sjacqu01
class kqueue_reactor
52 2486 sjacqu01
  : public boost::asio::detail::service_base<kqueue_reactor>
53 2486 sjacqu01
{
54 2486 sjacqu01
public:
55 2486 sjacqu01
  enum op_types { read_op = 0, write_op = 1,
56 2486 sjacqu01
    connect_op = 1, except_op = 2, max_ops = 3 };
57 2486 sjacqu01
58 2486 sjacqu01
  // Per-descriptor queues.
59 2486 sjacqu01
  struct descriptor_state
60 2486 sjacqu01
  {
61 2486 sjacqu01
    friend class kqueue_reactor;
62 2486 sjacqu01
    friend class object_pool_access;
63 2486 sjacqu01
64 2486 sjacqu01
    descriptor_state* next_;
65 2486 sjacqu01
    descriptor_state* prev_;
66 2486 sjacqu01
67 2486 sjacqu01
    mutex mutex_;
68 2486 sjacqu01
    int descriptor_;
69 2486 sjacqu01
    int num_kevents_; // 1 == read only, 2 == read and write
70 2486 sjacqu01
    op_queue<reactor_op> op_queue_[max_ops];
71 2486 sjacqu01
    bool shutdown_;
72 2486 sjacqu01
  };
73 2486 sjacqu01
74 2486 sjacqu01
  // Per-descriptor data.
75 2486 sjacqu01
  typedef descriptor_state* per_descriptor_data;
76 2486 sjacqu01
77 2486 sjacqu01
  // Constructor.
78 2486 sjacqu01
  BOOST_ASIO_DECL kqueue_reactor(boost::asio::io_service& io_service);
79 2486 sjacqu01
80 2486 sjacqu01
  // Destructor.
81 2486 sjacqu01
  BOOST_ASIO_DECL ~kqueue_reactor();
82 2486 sjacqu01
83 2486 sjacqu01
  // Destroy all user-defined handler objects owned by the service.
84 2486 sjacqu01
  BOOST_ASIO_DECL void shutdown_service();
85 2486 sjacqu01
86 2486 sjacqu01
  // Recreate internal descriptors following a fork.
87 2486 sjacqu01
  BOOST_ASIO_DECL void fork_service(
88 2486 sjacqu01
      boost::asio::io_service::fork_event fork_ev);
89 2486 sjacqu01
90 2486 sjacqu01
  // Initialise the task.
91 2486 sjacqu01
  BOOST_ASIO_DECL void init_task();
92 2486 sjacqu01
93 2486 sjacqu01
  // Register a socket with the reactor. Returns 0 on success, system error
94 2486 sjacqu01
  // code on failure.
95 2486 sjacqu01
  BOOST_ASIO_DECL int register_descriptor(socket_type descriptor,
96 2486 sjacqu01
      per_descriptor_data& descriptor_data);
97 2486 sjacqu01
98 2486 sjacqu01
  // Register a descriptor with an associated single operation. Returns 0 on
99 2486 sjacqu01
  // success, system error code on failure.
100 2486 sjacqu01
  BOOST_ASIO_DECL int register_internal_descriptor(
101 2486 sjacqu01
      int op_type, socket_type descriptor,
102 2486 sjacqu01
      per_descriptor_data& descriptor_data, reactor_op* op);
103 2486 sjacqu01
104 2486 sjacqu01
  // Move descriptor registration from one descriptor_data object to another.
105 2486 sjacqu01
  BOOST_ASIO_DECL void move_descriptor(socket_type descriptor,
106 2486 sjacqu01
      per_descriptor_data& target_descriptor_data,
107 2486 sjacqu01
      per_descriptor_data& source_descriptor_data);
108 2486 sjacqu01
109 2486 sjacqu01
  // Post a reactor operation for immediate completion.
110 2486 sjacqu01
  void post_immediate_completion(reactor_op* op, bool is_continuation)
111 2486 sjacqu01
  {
112 2486 sjacqu01
    io_service_.post_immediate_completion(op, is_continuation);
113 2486 sjacqu01
  }
114 2486 sjacqu01
115 2486 sjacqu01
  // Start a new operation. The reactor operation will be performed when the
116 2486 sjacqu01
  // given descriptor is flagged as ready, or an error has occurred.
117 2486 sjacqu01
  BOOST_ASIO_DECL void start_op(int op_type, socket_type descriptor,
118 2486 sjacqu01
      per_descriptor_data& descriptor_data, reactor_op* op,
119 2486 sjacqu01
      bool is_continuation, bool allow_speculative);
120 2486 sjacqu01
121 2486 sjacqu01
  // Cancel all operations associated with the given descriptor. The
122 2486 sjacqu01
  // handlers associated with the descriptor will be invoked with the
123 2486 sjacqu01
  // operation_aborted error.
124 2486 sjacqu01
  BOOST_ASIO_DECL void cancel_ops(socket_type descriptor,
125 2486 sjacqu01
      per_descriptor_data& descriptor_data);
126 2486 sjacqu01
127 2486 sjacqu01
  // Cancel any operations that are running against the descriptor and remove
128 2486 sjacqu01
  // its registration from the reactor.
129 2486 sjacqu01
  BOOST_ASIO_DECL void deregister_descriptor(socket_type descriptor,
130 2486 sjacqu01
      per_descriptor_data& descriptor_data, bool closing);
131 2486 sjacqu01
132 2486 sjacqu01
  // Remote the descriptor's registration from the reactor.
133 2486 sjacqu01
  BOOST_ASIO_DECL void deregister_internal_descriptor(
134 2486 sjacqu01
      socket_type descriptor, per_descriptor_data& descriptor_data);
135 2486 sjacqu01
136 2486 sjacqu01
  // Add a new timer queue to the reactor.
137 2486 sjacqu01
  template <typename Time_Traits>
138 2486 sjacqu01
  void add_timer_queue(timer_queue<Time_Traits>& queue);
139 2486 sjacqu01
140 2486 sjacqu01
  // Remove a timer queue from the reactor.
141 2486 sjacqu01
  template <typename Time_Traits>
142 2486 sjacqu01
  void remove_timer_queue(timer_queue<Time_Traits>& queue);
143 2486 sjacqu01
144 2486 sjacqu01
  // Schedule a new operation in the given timer queue to expire at the
145 2486 sjacqu01
  // specified absolute time.
146 2486 sjacqu01
  template <typename Time_Traits>
147 2486 sjacqu01
  void schedule_timer(timer_queue<Time_Traits>& queue,
148 2486 sjacqu01
      const typename Time_Traits::time_type& time,
149 2486 sjacqu01
      typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op);
150 2486 sjacqu01
151 2486 sjacqu01
  // Cancel the timer operations associated with the given token. Returns the
152 2486 sjacqu01
  // number of operations that have been posted or dispatched.
153 2486 sjacqu01
  template <typename Time_Traits>
154 2486 sjacqu01
  std::size_t cancel_timer(timer_queue<Time_Traits>& queue,
155 2486 sjacqu01
      typename timer_queue<Time_Traits>::per_timer_data& timer,
156 2486 sjacqu01
      std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)());
157 2486 sjacqu01
158 2486 sjacqu01
  // Run the kqueue loop.
159 2486 sjacqu01
  BOOST_ASIO_DECL void run(bool block, op_queue<operation>& ops);
160 2486 sjacqu01
161 2486 sjacqu01
  // Interrupt the kqueue loop.
162 2486 sjacqu01
  BOOST_ASIO_DECL void interrupt();
163 2486 sjacqu01
164 2486 sjacqu01
private:
165 2486 sjacqu01
  // Create the kqueue file descriptor. Throws an exception if the descriptor
166 2486 sjacqu01
  // cannot be created.
167 2486 sjacqu01
  BOOST_ASIO_DECL static int do_kqueue_create();
168 2486 sjacqu01
169 2486 sjacqu01
  // Allocate a new descriptor state object.
170 2486 sjacqu01
  BOOST_ASIO_DECL descriptor_state* allocate_descriptor_state();
171 2486 sjacqu01
172 2486 sjacqu01
  // Free an existing descriptor state object.
173 2486 sjacqu01
  BOOST_ASIO_DECL void free_descriptor_state(descriptor_state* s);
174 2486 sjacqu01
175 2486 sjacqu01
  // Helper function to add a new timer queue.
176 2486 sjacqu01
  BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue);
177 2486 sjacqu01
178 2486 sjacqu01
  // Helper function to remove a timer queue.
179 2486 sjacqu01
  BOOST_ASIO_DECL void do_remove_timer_queue(timer_queue_base& queue);
180 2486 sjacqu01
181 2486 sjacqu01
  // Get the timeout value for the kevent call.
182 2486 sjacqu01
  BOOST_ASIO_DECL timespec* get_timeout(timespec& ts);
183 2486 sjacqu01
184 2486 sjacqu01
  // The io_service implementation used to post completions.
185 2486 sjacqu01
  io_service_impl& io_service_;
186 2486 sjacqu01
187 2486 sjacqu01
  // Mutex to protect access to internal data.
188 2486 sjacqu01
  mutex mutex_;
189 2486 sjacqu01
190 2486 sjacqu01
  // The kqueue file descriptor.
191 2486 sjacqu01
  int kqueue_fd_;
192 2486 sjacqu01
193 2486 sjacqu01
  // The interrupter is used to break a blocking kevent call.
194 2486 sjacqu01
  select_interrupter interrupter_;
195 2486 sjacqu01
196 2486 sjacqu01
  // The timer queues.
197 2486 sjacqu01
  timer_queue_set timer_queues_;
198 2486 sjacqu01
199 2486 sjacqu01
  // Whether the service has been shut down.
200 2486 sjacqu01
  bool shutdown_;
201 2486 sjacqu01
202 2486 sjacqu01
  // Mutex to protect access to the registered descriptors.
203 2486 sjacqu01
  mutex registered_descriptors_mutex_;
204 2486 sjacqu01
205 2486 sjacqu01
  // Keep track of all registered descriptors.
206 2486 sjacqu01
  object_pool<descriptor_state> registered_descriptors_;
207 2486 sjacqu01
};
208 2486 sjacqu01
209 2486 sjacqu01
} // namespace detail
210 2486 sjacqu01
} // namespace asio
211 2486 sjacqu01
} // namespace boost
212 2486 sjacqu01
213 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
214 2486 sjacqu01
215 2486 sjacqu01
#include <boost/asio/detail/impl/kqueue_reactor.hpp>
216 2486 sjacqu01
#if defined(BOOST_ASIO_HEADER_ONLY)
217 2486 sjacqu01
# include <boost/asio/detail/impl/kqueue_reactor.ipp>
218 2486 sjacqu01
#endif // defined(BOOST_ASIO_HEADER_ONLY)
219 2486 sjacqu01
220 2486 sjacqu01
#endif // defined(BOOST_ASIO_HAS_KQUEUE)
221 2486 sjacqu01
222 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_KQUEUE_REACTOR_HPP