| 1 | // Copyright (c) 2009 Dmitry Goncharov
|
|---|
| 2 | //
|
|---|
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|---|
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|---|
| 5 |
|
|---|
| 6 | #ifndef BOOST_ASIO_POSIX_SIGNAL_HANDLER_HPP
|
|---|
| 7 | #define BOOST_ASIO_POSIX_SIGNAL_HANDLER_HPP
|
|---|
| 8 |
|
|---|
| 9 | #include <boost/asio/io_service.hpp>
|
|---|
| 10 | #include <boost/asio/posix/stream_descriptor.hpp>
|
|---|
| 11 | #include <boost/asio/read.hpp>
|
|---|
| 12 | #include <boost/asio/posix/signalfd.hpp>
|
|---|
| 13 |
|
|---|
| 14 | #if defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR) \
|
|---|
| 15 | || defined(GENERATING_DOCUMENTATION)
|
|---|
| 16 |
|
|---|
| 17 | namespace boost { namespace asio { namespace posix {
|
|---|
| 18 |
|
|---|
| 19 | template <int Signo>
|
|---|
| 20 | class signal_handler
|
|---|
| 21 | {
|
|---|
| 22 | public:
|
|---|
| 23 | explicit signal_handler(io_service& ios)
|
|---|
| 24 | : m_sd(ios, m_sigfd.fd())
|
|---|
| 25 | {}
|
|---|
| 26 |
|
|---|
| 27 | template <typename Handler>
|
|---|
| 28 | void async_wait(Handler h)
|
|---|
| 29 | {
|
|---|
| 30 | async_read(m_sd, buffer(&m_buf, sizeof m_buf), h);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | private:
|
|---|
| 34 | signal_handler(signal_handler const&);
|
|---|
| 35 | signal_handler const& operator=(signal_handler const&);
|
|---|
| 36 |
|
|---|
| 37 | private:
|
|---|
| 38 | signalfd<Signo> m_sigfd;
|
|---|
| 39 | stream_descriptor m_sd;
|
|---|
| 40 | typename signalfd<Signo>::buf_type m_buf;
|
|---|
| 41 | };
|
|---|
| 42 |
|
|---|
| 43 | }}}
|
|---|
| 44 |
|
|---|
| 45 | #endif // defined(BOOST_ASIO_HAS_POSIX_STREAM_DESCRIPTOR)
|
|---|
| 46 | // || defined(GENERATING_DOCUMENTATION)
|
|---|
| 47 | #endif
|
|---|
| 48 |
|
|---|