pipe_select_interrupter.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // detail/pipe_select_interrupter.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 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_PIPE_SELECT_INTERRUPTER_HPP
  11. #define BOOST_ASIO_DETAIL_PIPE_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)
  17. #if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  18. #if !defined(__CYGWIN__)
  19. #if !defined(__SYMBIAN32__)
  20. #if !defined(BOOST_ASIO_HAS_EVENTFD)
  21. #include <boost/asio/detail/push_options.hpp>
  22. namespace boost {
  23. namespace asio {
  24. namespace detail {
  25. class pipe_select_interrupter
  26. {
  27. public:
  28. // Constructor.
  29. BOOST_ASIO_DECL pipe_select_interrupter();
  30. // Destructor.
  31. BOOST_ASIO_DECL ~pipe_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 interrupter. Returns true if the reset was successful.
  37. BOOST_ASIO_DECL bool reset();
  38. // Get the read descriptor to be passed to select.
  39. int 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. int 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. int 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/pipe_select_interrupter.ipp>
  64. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  65. #endif // !defined(BOOST_ASIO_HAS_EVENTFD)
  66. #endif // !defined(__SYMBIAN32__)
  67. #endif // !defined(__CYGWIN__)
  68. #endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
  69. #endif // !defined(BOOST_ASIO_WINDOWS)
  70. #endif // BOOST_ASIO_DETAIL_PIPE_SELECT_INTERRUPTER_HPP