socket_select_interrupter.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // detail/socket_select_interrupter.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 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. #ifndef BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP
  11. #define BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  17. #if defined(BOOST_ASIO_WINDOWS) \
  18. || defined(__CYGWIN__) \
  19. || defined(__SYMBIAN32__)
  20. #include <boost/asio/detail/socket_types.hpp>
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. namespace detail {
  25. class socket_select_interrupter
  26. {
  27. public:
  28. // Constructor.
  29. BOOST_ASIO_DECL socket_select_interrupter();
  30. // Destructor.
  31. BOOST_ASIO_DECL ~socket_select_interrupter();
  32. // Recreate the interrupter's descriptors. Used after a fork.
  33. BOOST_ASIO_DECL void recreate();
  34. // Interrupt the select call.
  35. BOOST_ASIO_DECL void interrupt();
  36. // Reset the select interrupt. Returns true if the call was interrupted.
  37. BOOST_ASIO_DECL bool reset();
  38. // Get the read descriptor to be passed to select.
  39. socket_type read_descriptor() const
  40. {
  41. return read_descriptor_;
  42. }
  43. private:
  44. // Open the descriptors. Throws on error.
  45. BOOST_ASIO_DECL void open_descriptors();
  46. // Close the descriptors.
  47. BOOST_ASIO_DECL void close_descriptors();
  48. // The read end of a connection used to interrupt the select call. This file
  49. // descriptor is passed to select such that when it is time to stop, a single
  50. // byte will be written on the other end of the connection and this
  51. // descriptor will become readable.
  52. socket_type read_descriptor_;
  53. // The write end of a connection used to interrupt the select call. A single
  54. // byte may be written to this to wake up the select which is waiting for the
  55. // other end to become readable.
  56. socket_type write_descriptor_;
  57. };
  58. } // namespace detail
  59. } // namespace asio
  60. } // namespace boost
  61. #include <boost/asio/detail/pop_options.hpp>
  62. #if defined(BOOST_ASIO_HEADER_ONLY)
  63. # include <boost/asio/detail/impl/socket_select_interrupter.ipp>
  64. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  65. #endif // defined(BOOST_ASIO_WINDOWS)
  66. // || defined(__CYGWIN__)
  67. // || defined(__SYMBIAN32__)
  68. #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  69. #endif // BOOST_ASIO_DETAIL_SOCKET_SELECT_INTERRUPTER_HPP