From 76b13a741a4d5d87b31a4d6df43b0341ec304eae Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Sun, 24 Nov 2013 13:00:21 -0500 Subject: [PATCH] adding missing files --- CMakeLists.txt | 1 + include/fc/interprocess/signals.hpp | 8 ++++++++ src/asio.cpp | 2 +- src/interprocess/signals.cpp | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 include/fc/interprocess/signals.hpp create mode 100644 src/interprocess/signals.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a41dffb..76225be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,7 @@ set( fc_sources src/io/varint.cpp src/filesystem.cpp src/interprocess/process.cpp + src/interprocess/signals.cpp src/interprocess/file_mapping.cpp src/interprocess/mmap_struct.cpp src/rpc/json_connection.cpp diff --git a/include/fc/interprocess/signals.hpp b/include/fc/interprocess/signals.hpp new file mode 100644 index 0000000..876c684 --- /dev/null +++ b/include/fc/interprocess/signals.hpp @@ -0,0 +1,8 @@ +#pragma once +#include + +namespace fc +{ + /// handler will be called from ASIO thread + void set_signal_handler( std::function handler, int signal_num ); +} diff --git a/src/asio.cpp b/src/asio.cpp index 33333e7..57b7cca 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -106,7 +106,7 @@ namespace fc { { delete the_work; io->stop(); - asio_thread->join(); + // TODO: this hangs sometimes.. asio_thread->join(); delete io; delete asio_thread; } diff --git a/src/interprocess/signals.cpp b/src/interprocess/signals.cpp new file mode 100644 index 0000000..f65f122 --- /dev/null +++ b/src/interprocess/signals.cpp @@ -0,0 +1,17 @@ +#include +#include + +namespace fc +{ + void set_signal_handler( std::function handler, int signal_num ) + { + std::shared_ptr sig_set(new boost::asio::signal_set(fc::asio::default_io_service(), signal_num)); + sig_set->async_wait( + [sig_set,handler]( const boost::system::error_code& err, int num ) + { + handler( num ); + sig_set->cancel(); + // set_signal_handler( handler, signal_num ); + } ); + } +}