summaryrefslogtreecommitdiff
path: root/boost/asio/detail/impl/signal_set_service.ipp
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2014-12-11 09:55:56 (GMT)
committerChanho Park <chanho61.park@samsung.com>2014-12-11 09:55:56 (GMT)
commit08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch)
tree7a7053ceb8874b28ec4b868d4c49b500008a102e /boost/asio/detail/impl/signal_set_service.ipp
parentbb4dd8289b351fae6b55e303f189127a394a1edd (diff)
downloadboost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'boost/asio/detail/impl/signal_set_service.ipp')
-rw-r--r--boost/asio/detail/impl/signal_set_service.ipp158
1 files changed, 107 insertions, 51 deletions
diff --git a/boost/asio/detail/impl/signal_set_service.ipp b/boost/asio/detail/impl/signal_set_service.ipp
index 0b57007..21be62f 100644
--- a/boost/asio/detail/impl/signal_set_service.ipp
+++ b/boost/asio/detail/impl/signal_set_service.ipp
@@ -2,7 +2,7 @@
// detail/impl/signal_set_service.ipp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2014 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -57,25 +57,33 @@ signal_state* get_signal_state()
return &state;
}
-void asio_signal_handler(int signal_number)
+void boost_asio_signal_handler(int signal_number)
{
-#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+#if defined(BOOST_ASIO_WINDOWS) \
+ || defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ || defined(__CYGWIN__)
signal_set_service::deliver_signal(signal_number);
-#else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+#else // defined(BOOST_ASIO_WINDOWS)
+ // || defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // || defined(__CYGWIN__)
int saved_errno = errno;
signal_state* state = get_signal_state();
- int result = ::write(state->write_descriptor_,
+ signed_size_type result = ::write(state->write_descriptor_,
&signal_number, sizeof(signal_number));
(void)result;
errno = saved_errno;
-#endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+#endif // defined(BOOST_ASIO_WINDOWS)
+ // || defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // || defined(__CYGWIN__)
#if defined(BOOST_ASIO_HAS_SIGNAL) && !defined(BOOST_ASIO_HAS_SIGACTION)
- ::signal(signal_number, asio_signal_handler);
+ ::signal(signal_number, boost_asio_signal_handler);
#endif // defined(BOOST_ASIO_HAS_SIGNAL) && !defined(BOOST_ASIO_HAS_SIGACTION)
}
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) \
+ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ && !defined(__CYGWIN__)
class signal_set_service::pipe_read_op : public reactor_op
{
public:
@@ -105,22 +113,32 @@ public:
delete o;
}
};
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
signal_set_service::signal_set_service(
boost::asio::io_service& io_service)
: io_service_(boost::asio::use_service<io_service_impl>(io_service)),
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) \
+ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ && !defined(__CYGWIN__)
reactor_(boost::asio::use_service<reactor>(io_service)),
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
next_(0),
prev_(0)
{
get_signal_state()->mutex_.init();
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) \
+ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ && !defined(__CYGWIN__)
reactor_.init_task();
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
for (int i = 0; i < max_signal_number; ++i)
registrations_[i] = 0;
@@ -155,21 +173,31 @@ void signal_set_service::shutdown_service()
void signal_set_service::fork_service(
boost::asio::io_service::fork_event fork_ev)
{
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) \
+ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ && !defined(__CYGWIN__)
signal_state* state = get_signal_state();
static_mutex::scoped_lock lock(state->mutex_);
switch (fork_ev)
{
case boost::asio::io_service::fork_prepare:
- reactor_.deregister_internal_descriptor(
- state->read_descriptor_, reactor_data_);
- state->fork_prepared_ = true;
+ {
+ int read_descriptor = state->read_descriptor_;
+ state->fork_prepared_ = true;
+ lock.unlock();
+ reactor_.deregister_internal_descriptor(read_descriptor, reactor_data_);
+ }
break;
case boost::asio::io_service::fork_parent:
- state->fork_prepared_ = false;
- reactor_.register_internal_descriptor(reactor::read_op,
- state->read_descriptor_, reactor_data_, new pipe_read_op);
+ if (state->fork_prepared_)
+ {
+ int read_descriptor = state->read_descriptor_;
+ state->fork_prepared_ = false;
+ lock.unlock();
+ reactor_.register_internal_descriptor(reactor::read_op,
+ read_descriptor, reactor_data_, new pipe_read_op);
+ }
break;
case boost::asio::io_service::fork_child:
if (state->fork_prepared_)
@@ -177,17 +205,23 @@ void signal_set_service::fork_service(
boost::asio::detail::signal_blocker blocker;
close_descriptors();
open_descriptors();
+ int read_descriptor = state->read_descriptor_;
state->fork_prepared_ = false;
+ lock.unlock();
+ reactor_.register_internal_descriptor(reactor::read_op,
+ read_descriptor, reactor_data_, new pipe_read_op);
}
- reactor_.register_internal_descriptor(reactor::read_op,
- state->read_descriptor_, reactor_data_, new pipe_read_op);
break;
default:
break;
}
-#else // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#else // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
(void)fork_ev;
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
}
void signal_set_service::construct(
@@ -209,7 +243,7 @@ boost::system::error_code signal_set_service::add(
int signal_number, boost::system::error_code& ec)
{
// Check that the signal number is valid.
- if (signal_number < 0 || signal_number > max_signal_number)
+ if (signal_number < 0 || signal_number >= max_signal_number)
{
ec = boost::asio::error::invalid_argument;
return ec;
@@ -240,19 +274,19 @@ boost::system::error_code signal_set_service::add(
using namespace std; // For memset.
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
- sa.sa_handler = asio_signal_handler;
+ sa.sa_handler = boost_asio_signal_handler;
sigfillset(&sa.sa_mask);
if (::sigaction(signal_number, &sa, 0) == -1)
# else // defined(BOOST_ASIO_HAS_SIGACTION)
- if (::signal(signal_number, asio_signal_handler) == SIG_ERR)
+ if (::signal(signal_number, boost_asio_signal_handler) == SIG_ERR)
# endif // defined(BOOST_ASIO_HAS_SIGACTION)
{
-# if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
ec = boost::asio::error::invalid_argument;
-# else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
ec = boost::system::error_code(errno,
boost::asio::error::get_system_category());
-# endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
delete new_registration;
return ec;
}
@@ -283,7 +317,7 @@ boost::system::error_code signal_set_service::remove(
int signal_number, boost::system::error_code& ec)
{
// Check that the signal number is valid.
- if (signal_number < 0 || signal_number > max_signal_number)
+ if (signal_number < 0 || signal_number >= max_signal_number)
{
ec = boost::asio::error::invalid_argument;
return ec;
@@ -317,12 +351,12 @@ boost::system::error_code signal_set_service::remove(
if (::signal(signal_number, SIG_DFL) == SIG_ERR)
# endif // defined(BOOST_ASIO_HAS_SIGACTION)
{
-# if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
ec = boost::asio::error::invalid_argument;
-# else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
ec = boost::system::error_code(errno,
boost::asio::error::get_system_category());
-# endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
return ec;
}
}
@@ -371,12 +405,12 @@ boost::system::error_code signal_set_service::clear(
if (::signal(reg->signal_number_, SIG_DFL) == SIG_ERR)
# endif // defined(BOOST_ASIO_HAS_SIGACTION)
{
-# if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# if defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
ec = boost::asio::error::invalid_argument;
-# else // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# else // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
ec = boost::system::error_code(errno,
boost::asio::error::get_system_category());
-# endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
+# endif // defined(BOOST_ASIO_WINDOWS) || defined(__CYGWIN__)
return ec;
}
}
@@ -466,11 +500,11 @@ void signal_set_service::add_service(signal_set_service* service)
signal_state* state = get_signal_state();
static_mutex::scoped_lock lock(state->mutex_);
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
// If this is the first service to be created, open a new pipe.
if (state->service_list_ == 0)
open_descriptors();
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
// Insert service into linked list of all services.
service->next_ = state->service_list_;
@@ -479,11 +513,17 @@ void signal_set_service::add_service(signal_set_service* service)
state->service_list_->prev_ = service;
state->service_list_ = service;
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) \
+ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ && !defined(__CYGWIN__)
// Register for pipe readiness notifications.
+ int read_descriptor = state->read_descriptor_;
+ lock.unlock();
service->reactor_.register_internal_descriptor(reactor::read_op,
- state->read_descriptor_, service->reactor_data_, new pipe_read_op);
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+ read_descriptor, service->reactor_data_, new pipe_read_op);
+#endif // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
}
void signal_set_service::remove_service(signal_set_service* service)
@@ -493,11 +533,18 @@ void signal_set_service::remove_service(signal_set_service* service)
if (service->next_ || service->prev_ || state->service_list_ == service)
{
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) \
+ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ && !defined(__CYGWIN__)
// Disable the pipe readiness notifications.
+ int read_descriptor = state->read_descriptor_;
+ lock.unlock();
service->reactor_.deregister_descriptor(
- state->read_descriptor_, service->reactor_data_, false);
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+ read_descriptor, service->reactor_data_, false);
+ lock.lock();
+#endif // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
// Remove service from linked list of all services.
if (state->service_list_ == service)
@@ -509,17 +556,19 @@ void signal_set_service::remove_service(signal_set_service* service)
service->next_ = 0;
service->prev_ = 0;
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
// If this is the last service to be removed, close the pipe.
if (state->service_list_ == 0)
close_descriptors();
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_WINDOWS) && !defined(__CYGWIN__)
}
}
void signal_set_service::open_descriptors()
{
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) \
+ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ && !defined(__CYGWIN__)
signal_state* state = get_signal_state();
int pipe_fds[2];
@@ -542,12 +591,16 @@ void signal_set_service::open_descriptors()
boost::asio::error::get_system_category());
boost::asio::detail::throw_error(ec, "signal_set_service pipe");
}
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
}
void signal_set_service::close_descriptors()
{
-#if !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#if !defined(BOOST_ASIO_WINDOWS) \
+ && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \
+ && !defined(__CYGWIN__)
signal_state* state = get_signal_state();
if (state->read_descriptor_ != -1)
@@ -557,7 +610,9 @@ void signal_set_service::close_descriptors()
if (state->write_descriptor_ != -1)
::close(state->write_descriptor_);
state->write_descriptor_ = -1;
-#endif // !defined(BOOST_WINDOWS) && !defined(__CYGWIN__)
+#endif // !defined(BOOST_ASIO_WINDOWS)
+ // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
+ // && !defined(__CYGWIN__)
}
void signal_set_service::start_wait_op(
@@ -574,6 +629,7 @@ void signal_set_service::start_wait_op(
if (reg->undelivered_ > 0)
{
--reg->undelivered_;
+ op->signal_number_ = reg->signal_number_;
io_service_.post_deferred_completion(op);
return;
}