Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / asio / detail / impl / pipe_select_interrupter.ipp @ 2486

History | View | Annotate | Download (3.1 kB)

1 2486 sjacqu01
//
2 2486 sjacqu01
// detail/impl/pipe_select_interrupter.ipp
3 2486 sjacqu01
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 2486 sjacqu01
//
5 2486 sjacqu01
// Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 2486 sjacqu01
//
7 2486 sjacqu01
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8 2486 sjacqu01
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 2486 sjacqu01
//
10 2486 sjacqu01
11 2486 sjacqu01
#ifndef BOOST_ASIO_DETAIL_IMPL_PIPE_SELECT_INTERRUPTER_IPP
12 2486 sjacqu01
#define BOOST_ASIO_DETAIL_IMPL_PIPE_SELECT_INTERRUPTER_IPP
13 2486 sjacqu01
14 2486 sjacqu01
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 2486 sjacqu01
# pragma once
16 2486 sjacqu01
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 2486 sjacqu01
18 2486 sjacqu01
#include <boost/asio/detail/config.hpp>
19 2486 sjacqu01
20 2486 sjacqu01
#if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
21 2486 sjacqu01
#if !defined(BOOST_ASIO_WINDOWS)
22 2486 sjacqu01
#if !defined(__CYGWIN__)
23 2486 sjacqu01
#if !defined(__SYMBIAN32__)
24 2486 sjacqu01
#if !defined(BOOST_ASIO_HAS_EVENTFD)
25 2486 sjacqu01
26 2486 sjacqu01
#include <fcntl.h>
27 2486 sjacqu01
#include <sys/stat.h>
28 2486 sjacqu01
#include <sys/types.h>
29 2486 sjacqu01
#include <unistd.h>
30 2486 sjacqu01
#include <boost/asio/detail/pipe_select_interrupter.hpp>
31 2486 sjacqu01
#include <boost/asio/detail/socket_types.hpp>
32 2486 sjacqu01
#include <boost/asio/detail/throw_error.hpp>
33 2486 sjacqu01
#include <boost/asio/error.hpp>
34 2486 sjacqu01
35 2486 sjacqu01
#include <boost/asio/detail/push_options.hpp>
36 2486 sjacqu01
37 2486 sjacqu01
namespace boost {
38 2486 sjacqu01
namespace asio {
39 2486 sjacqu01
namespace detail {
40 2486 sjacqu01
41 2486 sjacqu01
pipe_select_interrupter::pipe_select_interrupter()
42 2486 sjacqu01
{
43 2486 sjacqu01
  open_descriptors();
44 2486 sjacqu01
}
45 2486 sjacqu01
46 2486 sjacqu01
void pipe_select_interrupter::open_descriptors()
47 2486 sjacqu01
{
48 2486 sjacqu01
  int pipe_fds[2];
49 2486 sjacqu01
  if (pipe(pipe_fds) == 0)
50 2486 sjacqu01
  {
51 2486 sjacqu01
    read_descriptor_ = pipe_fds[0];
52 2486 sjacqu01
    ::fcntl(read_descriptor_, F_SETFL, O_NONBLOCK);
53 2486 sjacqu01
    write_descriptor_ = pipe_fds[1];
54 2486 sjacqu01
    ::fcntl(write_descriptor_, F_SETFL, O_NONBLOCK);
55 2486 sjacqu01
56 2486 sjacqu01
#if defined(FD_CLOEXEC)
57 2486 sjacqu01
    ::fcntl(read_descriptor_, F_SETFD, FD_CLOEXEC);
58 2486 sjacqu01
    ::fcntl(write_descriptor_, F_SETFD, FD_CLOEXEC);
59 2486 sjacqu01
#endif // defined(FD_CLOEXEC)
60 2486 sjacqu01
  }
61 2486 sjacqu01
  else
62 2486 sjacqu01
  {
63 2486 sjacqu01
    boost::system::error_code ec(errno,
64 2486 sjacqu01
        boost::asio::error::get_system_category());
65 2486 sjacqu01
    boost::asio::detail::throw_error(ec, "pipe_select_interrupter");
66 2486 sjacqu01
  }
67 2486 sjacqu01
}
68 2486 sjacqu01
69 2486 sjacqu01
pipe_select_interrupter::~pipe_select_interrupter()
70 2486 sjacqu01
{
71 2486 sjacqu01
  close_descriptors();
72 2486 sjacqu01
}
73 2486 sjacqu01
74 2486 sjacqu01
void pipe_select_interrupter::close_descriptors()
75 2486 sjacqu01
{
76 2486 sjacqu01
  if (read_descriptor_ != -1)
77 2486 sjacqu01
    ::close(read_descriptor_);
78 2486 sjacqu01
  if (write_descriptor_ != -1)
79 2486 sjacqu01
    ::close(write_descriptor_);
80 2486 sjacqu01
}
81 2486 sjacqu01
82 2486 sjacqu01
void pipe_select_interrupter::recreate()
83 2486 sjacqu01
{
84 2486 sjacqu01
  close_descriptors();
85 2486 sjacqu01
86 2486 sjacqu01
  write_descriptor_ = -1;
87 2486 sjacqu01
  read_descriptor_ = -1;
88 2486 sjacqu01
89 2486 sjacqu01
  open_descriptors();
90 2486 sjacqu01
}
91 2486 sjacqu01
92 2486 sjacqu01
void pipe_select_interrupter::interrupt()
93 2486 sjacqu01
{
94 2486 sjacqu01
  char byte = 0;
95 2486 sjacqu01
  signed_size_type result = ::write(write_descriptor_, &byte, 1);
96 2486 sjacqu01
  (void)result;
97 2486 sjacqu01
}
98 2486 sjacqu01
99 2486 sjacqu01
bool pipe_select_interrupter::reset()
100 2486 sjacqu01
{
101 2486 sjacqu01
  for (;;)
102 2486 sjacqu01
  {
103 2486 sjacqu01
    char data[1024];
104 2486 sjacqu01
    signed_size_type bytes_read = ::read(read_descriptor_, data, sizeof(data));
105 2486 sjacqu01
    if (bytes_read < 0 && errno == EINTR)
106 2486 sjacqu01
      continue;
107 2486 sjacqu01
    bool was_interrupted = (bytes_read > 0);
108 2486 sjacqu01
    while (bytes_read == sizeof(data))
109 2486 sjacqu01
      bytes_read = ::read(read_descriptor_, data, sizeof(data));
110 2486 sjacqu01
    return was_interrupted;
111 2486 sjacqu01
  }
112 2486 sjacqu01
}
113 2486 sjacqu01
114 2486 sjacqu01
} // namespace detail
115 2486 sjacqu01
} // namespace asio
116 2486 sjacqu01
} // namespace boost
117 2486 sjacqu01
118 2486 sjacqu01
#include <boost/asio/detail/pop_options.hpp>
119 2486 sjacqu01
120 2486 sjacqu01
#endif // !defined(BOOST_ASIO_HAS_EVENTFD)
121 2486 sjacqu01
#endif // !defined(__SYMBIAN32__)
122 2486 sjacqu01
#endif // !defined(__CYGWIN__)
123 2486 sjacqu01
#endif // !defined(BOOST_ASIO_WINDOWS)
124 2486 sjacqu01
#endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
125 2486 sjacqu01
126 2486 sjacqu01
#endif // BOOST_ASIO_DETAIL_IMPL_PIPE_SELECT_INTERRUPTER_IPP