socket_select_interrupter.hpp 2.1 KB

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