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