10ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
20ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// detail/pipe_select_interrupter.hpp
30ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
50ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
60ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
70ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// Distributed under the Boost Software License, Version 1.0. (See accompanying
80ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
90ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie//
100ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
110ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#ifndef ASIO_DETAIL_PIPE_SELECT_INTERRUPTER_HPP
120ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#define ASIO_DETAIL_PIPE_SELECT_INTERRUPTER_HPP
130ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
140ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
150ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/config.hpp"
160ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
170ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
180ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/push_options.hpp"
190ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
200ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace asio {
210ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffienamespace detail {
220ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
230ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieclass pipe_select_interrupter
240ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie{
250ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffiepublic:
260ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Constructor.
270ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  ASIO_DECL pipe_select_interrupter();
280ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
290ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Destructor.
300ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  ASIO_DECL ~pipe_select_interrupter();
310ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
320ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Recreate the interrupter's descriptors. Used after a fork.
330ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  ASIO_DECL void recreate();
340ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
350ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Interrupt the select call.
360ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  ASIO_DECL void interrupt();
370ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
380ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Reset the select interrupt. Returns true if the call was interrupted.
390ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  ASIO_DECL bool reset();
400ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
410ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Get the read descriptor to be passed to select.
420ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  int read_descriptor() const
430ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  {
440ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie    return read_descriptor_;
450ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  }
460ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
470ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffieprivate:
480ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Open the descriptors. Throws on error.
490ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  ASIO_DECL void open_descriptors();
500ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
510ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // Close the descriptors.
520ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  ASIO_DECL void close_descriptors();
530ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
540ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // The read end of a connection used to interrupt the select call. This file
550ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // descriptor is passed to select such that when it is time to stop, a single
560ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // byte will be written on the other end of the connection and this
570ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // descriptor will become readable.
580ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  int read_descriptor_;
590ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
600ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // The write end of a connection used to interrupt the select call. A single
610ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // byte may be written to this to wake up the select which is waiting for the
620ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  // other end to become readable.
630ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie  int write_descriptor_;
640ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie};
650ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
660ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace detail
670ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie} // namespace asio
680ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
690ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#include "asio/detail/pop_options.hpp"
700ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
710ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie# include "asio/detail/impl/pipe_select_interrupter.ipp"
720ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
730ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie
740ee85db398be8ea33d67cc42f99a1468cd6c8180François Gaffie#endif // ASIO_DETAIL_PIPE_SELECT_INTERRUPTER_HPP
75