1 // 2 // detail/socket_select_interrupter.hpp 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 // 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com) 6 // 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 // 10 11 #ifndef BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP 12 #define BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP 13 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 15 # pragma once 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 17 18 #include <boost/asio/detail/config.hpp> 19 20 #if !defined(BOOST_ASIO_WINDOWS_RUNTIME) 21 22 #if defined(BOOST_ASIO_WINDOWS) \ 23 || defined(__CYGWIN__) \ 24 || defined(__SYMBIAN32__) 25 26 #include <boost/asio/detail/socket_types.hpp> 27 28 #include <boost/asio/detail/push_options.hpp> 29 30 namespace boost { 31 namespace asio { 32 namespace detail { 33 34 class socket_select_interrupter 35 { 36 public: 37 // Constructor. 38 BOOST_ASIO_DECL socket_select_interrupter(); 39 40 // Destructor. 41 BOOST_ASIO_DECL ~socket_select_interrupter(); 42 43 // Recreate the interrupter's descriptors. Used after a fork. 44 BOOST_ASIO_DECL void recreate(); 45 46 // Interrupt the select call. 47 BOOST_ASIO_DECL void interrupt(); 48 49 // Reset the select interrupt. Returns true if the call was interrupted. 50 BOOST_ASIO_DECL bool reset(); 51 52 // Get the read descriptor to be passed to select. read_descriptor() const53 socket_type read_descriptor() const 54 { 55 return read_descriptor_; 56 } 57 58 private: 59 // Open the descriptors. Throws on error. 60 BOOST_ASIO_DECL void open_descriptors(); 61 62 // Close the descriptors. 63 BOOST_ASIO_DECL void close_descriptors(); 64 65 // The read end of a connection used to interrupt the select call. This file 66 // descriptor is passed to select such that when it is time to stop, a single 67 // byte will be written on the other end of the connection and this 68 // descriptor will become readable. 69 socket_type read_descriptor_; 70 71 // The write end of a connection used to interrupt the select call. A single 72 // byte may be written to this to wake up the select which is waiting for the 73 // other end to become readable. 74 socket_type write_descriptor_; 75 }; 76 77 } // namespace detail 78 } // namespace asio 79 } // namespace boost 80 81 #include <boost/asio/detail/pop_options.hpp> 82 83 #if defined(BOOST_ASIO_HEADER_ONLY) 84 # include <boost/asio/detail/impl/socket_select_interrupter.ipp> 85 #endif // defined(BOOST_ASIO_HEADER_ONLY) 86 87 #endif // defined(BOOST_ASIO_WINDOWS) 88 // || defined(__CYGWIN__) 89 // || defined(__SYMBIAN32__) 90 91 #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME) 92 93 #endif // BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP 94