Gracefully shutdown debugproxy when sent SIGTERM 88/185688/2
authorIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Fri, 20 Jul 2018 12:30:26 +0000 (14:30 +0200)
committerIgor Kotrasinski <i.kotrasinsk@partner.samsung.com>
Tue, 21 Aug 2018 10:37:29 +0000 (12:37 +0200)
Change-Id: Idfb58076028d9c78e2ac297927d99c2da75217b2
Signed-off-by: Igor Kotrasinski <i.kotrasinsk@partner.samsung.com>
simulatordaemon/debugproxy/CMakeLists.txt
simulatordaemon/debugproxy/inc/DebugproxySocket.h
simulatordaemon/debugproxy/src/DebugproxySocket.cpp
simulatordaemon/debugproxy/src/main.cpp

index 32c7503..b55eaaf 100644 (file)
@@ -43,7 +43,7 @@ LINK_DIRECTORIES(
 )
 
 TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_DEBUGPROXY}
-    boost_system boost_signals boost_coroutine
+    boost_system boost_signals boost_coroutine pthread
     ${TARGET_TEF_SIMULATOR_LOG}
     ${DEBUGPROXY_DEPS_LIBRARIES}
     )
index f6eaff5..d07d4a4 100644 (file)
@@ -13,11 +13,11 @@ class DebugproxySocket
 public:
        DebugproxySocket(boost::asio::io_service &io);
        void start_accept();
+       void shutdown();
 private:
        void async_accept(yield_ctx yield);
        void handle_connection(std::shared_ptr<local_sock> local_sock,
                               yield_ctx yield);
-
        boost::asio::io_service &io;
        local::stream_protocol::endpoint ep;
        local::stream_protocol::acceptor acceptor;
index dcacf9a..fa586fb 100644 (file)
@@ -55,3 +55,10 @@ void DebugproxySocket::handle_connection(const std::shared_ptr<local_sock> local
                LOGE(MODULE_DEBUGPROXY, "Forwarding session ended: %s", e.what());
        }
 }
+
+void DebugproxySocket::shutdown()
+{
+       LOGD(MODULE_DEBUGPROXY, "Shutting down gracefully");
+       this->acceptor.cancel();
+       this->acceptor.close();
+}
index c53ae19..8febefc 100644 (file)
@@ -6,6 +6,13 @@ int main()
        boost::asio::io_service io;
        DebugproxySocket socket(io);
        socket.start_accept();
+
+       boost::asio::signal_set graceful_shutdown_sigs(io, SIGTERM);
+       graceful_shutdown_sigs.async_wait(
+               [&socket](const boost::system::error_code &e, int number) {
+                       socket.shutdown();
+               });
+
        io.run();
        return 0;
 }