eventfd_select_interrupter.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // detail/eventfd_select_interrupter.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. // Copyright (c) 2008 Roelof Naude (roelof.naude at gmail dot com)
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. #ifndef BOOST_ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP
  12. #define BOOST_ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP
  13. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  14. # pragma once
  15. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  16. #include <boost/asio/detail/config.hpp>
  17. #if defined(BOOST_ASIO_HAS_EVENTFD)
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace detail {
  22. class eventfd_select_interrupter
  23. {
  24. public:
  25. // Constructor.
  26. BOOST_ASIO_DECL eventfd_select_interrupter();
  27. // Destructor.
  28. BOOST_ASIO_DECL ~eventfd_select_interrupter();
  29. // Recreate the interrupter's descriptors. Used after a fork.
  30. BOOST_ASIO_DECL void recreate();
  31. // Interrupt the select call.
  32. BOOST_ASIO_DECL void interrupt();
  33. // Reset the select interrupt. Returns true if the call was interrupted.
  34. BOOST_ASIO_DECL bool reset();
  35. // Get the read descriptor to be passed to select.
  36. int read_descriptor() const
  37. {
  38. return read_descriptor_;
  39. }
  40. private:
  41. // Open the descriptors. Throws on error.
  42. BOOST_ASIO_DECL void open_descriptors();
  43. // Close the descriptors.
  44. BOOST_ASIO_DECL void close_descriptors();
  45. // The read end of a connection used to interrupt the select call. This file
  46. // descriptor is passed to select such that when it is time to stop, a single
  47. // 64bit value will be written on the other end of the connection and this
  48. // descriptor will become readable.
  49. int read_descriptor_;
  50. // The write end of a connection used to interrupt the select call. A single
  51. // 64bit non-zero value may be written to this to wake up the select which is
  52. // waiting for the other end to become readable. This descriptor will only
  53. // differ from the read descriptor when a pipe is used.
  54. int write_descriptor_;
  55. };
  56. } // namespace detail
  57. } // namespace asio
  58. } // namespace boost
  59. #include <boost/asio/detail/pop_options.hpp>
  60. #if defined(BOOST_ASIO_HEADER_ONLY)
  61. # include <boost/asio/detail/impl/eventfd_select_interrupter.ipp>
  62. #endif // defined(BOOST_ASIO_HEADER_ONLY)
  63. #endif // defined(BOOST_ASIO_HAS_EVENTFD)
  64. #endif // BOOST_ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP