eventfd_select_interrupter.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //
  2. // detail/eventfd_select_interrupter.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2011 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 ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP
  12. #define 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 "asio/detail/config.hpp"
  17. #if defined(ASIO_HAS_EVENTFD)
  18. #include "asio/detail/push_options.hpp"
  19. namespace asio {
  20. namespace detail {
  21. class eventfd_select_interrupter
  22. {
  23. public:
  24. // Constructor.
  25. ASIO_DECL eventfd_select_interrupter();
  26. // Destructor.
  27. ASIO_DECL ~eventfd_select_interrupter();
  28. // Interrupt the select call.
  29. ASIO_DECL void interrupt();
  30. // Reset the select interrupt. Returns true if the call was interrupted.
  31. ASIO_DECL bool reset();
  32. // Get the read descriptor to be passed to select.
  33. int read_descriptor() const
  34. {
  35. return read_descriptor_;
  36. }
  37. private:
  38. // The read end of a connection used to interrupt the select call. This file
  39. // descriptor is passed to select such that when it is time to stop, a single
  40. // 64bit value will be written on the other end of the connection and this
  41. // descriptor will become readable.
  42. int read_descriptor_;
  43. // The write end of a connection used to interrupt the select call. A single
  44. // 64bit non-zero value may be written to this to wake up the select which is
  45. // waiting for the other end to become readable. This descriptor will only
  46. // differ from the read descriptor when a pipe is used.
  47. int write_descriptor_;
  48. };
  49. } // namespace detail
  50. } // namespace asio
  51. #include "asio/detail/pop_options.hpp"
  52. #if defined(ASIO_HEADER_ONLY)
  53. # include "asio/detail/impl/eventfd_select_interrupter.ipp"
  54. #endif // defined(ASIO_HEADER_ONLY)
  55. #endif // defined(ASIO_HAS_EVENTFD)
  56. #endif // ASIO_DETAIL_EVENTFD_SELECT_INTERRUPTER_HPP