diff options
Diffstat (limited to '3rdParty/Boost/src/boost/asio/detail/epoll_reactor.hpp')
-rw-r--r-- | 3rdParty/Boost/src/boost/asio/detail/epoll_reactor.hpp | 76 |
1 files changed, 62 insertions, 14 deletions
diff --git a/3rdParty/Boost/src/boost/asio/detail/epoll_reactor.hpp b/3rdParty/Boost/src/boost/asio/detail/epoll_reactor.hpp index 1889017..8f66f74 100644 --- a/3rdParty/Boost/src/boost/asio/detail/epoll_reactor.hpp +++ b/3rdParty/Boost/src/boost/asio/detail/epoll_reactor.hpp @@ -2,7 +2,7 @@ // detail/epoll_reactor.hpp // ~~~~~~~~~~~~~~~~~~~~~~~~ // -// Copyright (c) 2003-2011 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -19,7 +19,10 @@ #if defined(BOOST_ASIO_HAS_EPOLL) +#include <boost/cstdint.hpp> +#include <boost/limits.hpp> #include <boost/asio/io_service.hpp> +#include <boost/asio/detail/atomic_count.hpp> #include <boost/asio/detail/epoll_reactor_fwd.hpp> #include <boost/asio/detail/mutex.hpp> #include <boost/asio/detail/object_pool.hpp> @@ -27,10 +30,10 @@ #include <boost/asio/detail/reactor_op.hpp> #include <boost/asio/detail/select_interrupter.hpp> #include <boost/asio/detail/socket_types.hpp> -#include <boost/asio/detail/timer_op.hpp> #include <boost/asio/detail/timer_queue_base.hpp> #include <boost/asio/detail/timer_queue_fwd.hpp> #include <boost/asio/detail/timer_queue_set.hpp> +#include <boost/asio/detail/wait_op.hpp> #include <boost/asio/detail/push_options.hpp> @@ -46,15 +49,27 @@ public: connect_op = 1, except_op = 2, max_ops = 3 }; // Per-descriptor queues. - class descriptor_state + class descriptor_state : operation { friend class epoll_reactor; friend class object_pool_access; + + descriptor_state* next_; + descriptor_state* prev_; + mutex mutex_; + epoll_reactor* reactor_; + int descriptor_; + boost::uint32_t registered_events_; op_queue<reactor_op> op_queue_[max_ops]; bool shutdown_; - descriptor_state* next_; - descriptor_state* prev_; + + BOOST_ASIO_DECL descriptor_state(); + void set_ready_events(uint32_t events) { task_result_ = events; } + BOOST_ASIO_DECL operation* perform_io(uint32_t events); + BOOST_ASIO_DECL static void do_complete( + io_service_impl* owner, operation* base, + const boost::system::error_code& ec, std::size_t bytes_transferred); }; // Per-descriptor data. @@ -69,6 +84,10 @@ public: // Destroy all user-defined handler objects owned by the service. BOOST_ASIO_DECL void shutdown_service(); + // Recreate internal descriptors following a fork. + BOOST_ASIO_DECL void fork_service( + boost::asio::io_service::fork_event fork_ev); + // Initialise the task. BOOST_ASIO_DECL void init_task(); @@ -77,6 +96,17 @@ public: BOOST_ASIO_DECL int register_descriptor(socket_type descriptor, per_descriptor_data& descriptor_data); + // Register a descriptor with an associated single operation. Returns 0 on + // success, system error code on failure. + BOOST_ASIO_DECL int register_internal_descriptor( + int op_type, socket_type descriptor, + per_descriptor_data& descriptor_data, reactor_op* op); + + // Move descriptor registration from one descriptor_data object to another. + BOOST_ASIO_DECL void move_descriptor(socket_type descriptor, + per_descriptor_data& target_descriptor_data, + per_descriptor_data& source_descriptor_data); + // Post a reactor operation for immediate completion. void post_immediate_completion(reactor_op* op) { @@ -86,8 +116,8 @@ public: // Start a new operation. The reactor operation will be performed when the // given descriptor is flagged as ready, or an error has occurred. BOOST_ASIO_DECL void start_op(int op_type, socket_type descriptor, - per_descriptor_data& descriptor_data, - reactor_op* op, bool allow_speculative); + per_descriptor_data& descriptor_data, reactor_op* op, + bool allow_speculative); // Cancel all operations associated with the given descriptor. The // handlers associated with the descriptor will be invoked with the @@ -97,8 +127,12 @@ public: // Cancel any operations that are running against the descriptor and remove // its registration from the reactor. - BOOST_ASIO_DECL void close_descriptor(socket_type descriptor, - per_descriptor_data& descriptor_data); + BOOST_ASIO_DECL void deregister_descriptor(socket_type descriptor, + per_descriptor_data& descriptor_data, bool closing); + + // Remote the descriptor's registration from the reactor. + BOOST_ASIO_DECL void deregister_internal_descriptor( + socket_type descriptor, per_descriptor_data& descriptor_data); // Add a new timer queue to the reactor. template <typename Time_Traits> @@ -113,13 +147,14 @@ public: template <typename Time_Traits> void schedule_timer(timer_queue<Time_Traits>& queue, const typename Time_Traits::time_type& time, - typename timer_queue<Time_Traits>::per_timer_data& timer, timer_op* op); + typename timer_queue<Time_Traits>::per_timer_data& timer, wait_op* op); // Cancel the timer operations associated with the given token. Returns the // number of operations that have been posted or dispatched. template <typename Time_Traits> std::size_t cancel_timer(timer_queue<Time_Traits>& queue, - typename timer_queue<Time_Traits>::per_timer_data& timer); + typename timer_queue<Time_Traits>::per_timer_data& timer, + std::size_t max_cancelled = (std::numeric_limits<std::size_t>::max)()); // Run epoll once until interrupted or events are ready to be dispatched. BOOST_ASIO_DECL void run(bool block, op_queue<operation>& ops); @@ -135,6 +170,15 @@ private: // cannot be created. BOOST_ASIO_DECL static int do_epoll_create(); + // Create the timerfd file descriptor. Does not throw. + BOOST_ASIO_DECL static int do_timerfd_create(); + + // Allocate a new descriptor state object. + BOOST_ASIO_DECL descriptor_state* allocate_descriptor_state(); + + // Free an existing descriptor state object. + BOOST_ASIO_DECL void free_descriptor_state(descriptor_state* s); + // Helper function to add a new timer queue. BOOST_ASIO_DECL void do_add_timer_queue(timer_queue_base& queue); @@ -161,15 +205,15 @@ private: // Mutex to protect access to internal data. mutex mutex_; + // The interrupter is used to break a blocking epoll_wait call. + select_interrupter interrupter_; + // The epoll file descriptor. int epoll_fd_; // The timer file descriptor. int timer_fd_; - // The interrupter is used to break a blocking epoll_wait call. - select_interrupter interrupter_; - // The timer queues. timer_queue_set timer_queues_; @@ -181,6 +225,10 @@ private: // Keep track of all registered descriptors. object_pool<descriptor_state> registered_descriptors_; + + // Helper class to do post-perform_io cleanup. + struct perform_io_cleanup_on_block_exit; + friend struct perform_io_cleanup_on_block_exit; }; } // namespace detail |