diff options
author | sangwan.kwon <sangwan.kwon@samsung.com> | 2016-05-20 10:11:55 +0900 |
---|---|---|
committer | sangwan.kwon <sangwan.kwon@samsung.com> | 2016-05-20 14:12:01 +0900 |
commit | a43bd5dbc3e73ddedd55b79d7ffc06ac62e1a2fd (patch) | |
tree | b604c78accddd8dbaefdc79d2e18c6e5eba65167 | |
parent | 21fd08ff2804662923e084d3bad9f304af6df8fc (diff) | |
download | cert-checker-a43bd5dbc3e73ddedd55b79d7ffc06ac62e1a2fd.tar.gz cert-checker-a43bd5dbc3e73ddedd55b79d7ffc06ac62e1a2fd.tar.bz2 cert-checker-a43bd5dbc3e73ddedd55b79d7ffc06ac62e1a2fd.zip |
Seperate logic to thread for several client connection
Change-Id: I8424f68e23f32cc8104c9c3987bc2054c6c034ad
-rw-r--r-- | src/main/cert-checker.cpp | 2 | ||||
-rw-r--r-- | src/service/logic.cpp | 6 | ||||
-rw-r--r-- | src/service/logic.h | 2 | ||||
-rw-r--r-- | src/service/ocsp-service.cpp | 10 | ||||
-rw-r--r-- | src/service/ocsp-service.h | 4 | ||||
-rw-r--r-- | tests/logic_.h | 4 | ||||
-rw-r--r-- | tests/test_logic.cpp | 6 |
7 files changed, 21 insertions, 13 deletions
diff --git a/src/main/cert-checker.cpp b/src/main/cert-checker.cpp index 389d37a..18fe21a 100644 --- a/src/main/cert-checker.cpp +++ b/src/main/cert-checker.cpp @@ -38,8 +38,6 @@ int main(void) setlocale(LC_ALL, ""); - // Set timeout about socket read event. - service.setTimeout(50); service.start(); LogInfo("Cert-checker exit!"); diff --git a/src/service/logic.cpp b/src/service/logic.cpp index aed5006..574b9b2 100644 --- a/src/service/logic.cpp +++ b/src/service/logic.cpp @@ -166,8 +166,8 @@ error_t Logic::setup() { // Check if setup was called if (m_was_setup_called) { - LogError("You can call setup only once"); - return INTERNAL_ERROR; + LogDebug("Setup is already done."); + return NO_ERROR; } m_was_setup_called = true; @@ -684,7 +684,7 @@ void Logic::set_should_exit(void) std::atomic<bool> Logic::m_is_first_run(false); -bool Logic::is_gmain_loop_running() +bool Logic::is_running() { return g_main_loop_is_running(m_loop); } diff --git a/src/service/logic.h b/src/service/logic.h index a7d9ff9..e2d5fd7 100644 --- a/src/service/logic.h +++ b/src/service/logic.h @@ -70,7 +70,7 @@ class Logic : public Timer { virtual ~Logic(void); error_t setup(void); void run(guint timeout); - bool is_gmain_loop_running(); + bool is_running(); virtual void clean(void); static void connman_callback(GDBusProxy *proxy, diff --git a/src/service/ocsp-service.cpp b/src/service/ocsp-service.cpp index 3f99da1..4c07fa6 100644 --- a/src/service/ocsp-service.cpp +++ b/src/service/ocsp-service.cpp @@ -33,6 +33,13 @@ OcspService::OcspService(const std::string &address) : OcspService::~OcspService() { + if(m_thread.joinable()) + m_thread.join(); +} + +void OcspService::run(void) +{ + m_logic.run(TIMEOUT_G_SERVICE); } void OcspService::onMessageProcess(const ConnShPtr &connection) @@ -43,7 +50,8 @@ void OcspService::onMessageProcess(const ConnShPtr &connection) connection->send(this->process(connection, in)); // Run gmainloop for event listening. - m_logic.run(TIMEOUT_G_SERVICE); + if(!m_logic.is_running()) + m_thread = std::thread(&OcspService::run,this); LogDebug("Finish processing message on ocsp service."); } diff --git a/src/service/ocsp-service.h b/src/service/ocsp-service.h index 3016967..8b29c57 100644 --- a/src/service/ocsp-service.h +++ b/src/service/ocsp-service.h @@ -22,6 +22,7 @@ #pragma once #include <string> +#include <thread> #include "common/service.h" #include "service/logic.h" @@ -37,9 +38,10 @@ public: private: virtual void onMessageProcess(const ConnShPtr &) override; - RawBuffer process(const ConnShPtr &, RawBuffer &); + void run(void); + std::thread m_thread; Logic m_logic; }; diff --git a/tests/logic_.h b/tests/logic_.h index 2a14a62..f8dcf95 100644 --- a/tests/logic_.h +++ b/tests/logic_.h @@ -93,9 +93,9 @@ public: { m_logic.run(timeout); } - bool is_gmain_loop_running() + bool is_running() { - return m_logic.is_gmain_loop_running(); + return m_logic.is_running(); } private: diff --git a/tests/test_logic.cpp b/tests/test_logic.cpp index 397b792..56c8290 100644 --- a/tests/test_logic.cpp +++ b/tests/test_logic.cpp @@ -59,10 +59,10 @@ BOOST_AUTO_TEST_CASE(logic_setup) { BOOST_REQUIRE(setup() == NO_ERROR); // double setup - BOOST_REQUIRE(setup() == INTERNAL_ERROR); + BOOST_REQUIRE(setup() == NO_ERROR); // double setup - BOOST_REQUIRE(setup() == INTERNAL_ERROR); + BOOST_REQUIRE(setup() == NO_ERROR); } BOOST_AUTO_TEST_CASE(logic_workflow_mixed) { @@ -466,7 +466,7 @@ BOOST_AUTO_TEST_CASE(logic_workflow_gio_timeout) { // Run gmainloop. run(3); - BOOST_REQUIRE(is_gmain_loop_running() == false); + BOOST_REQUIRE(is_running() == false); } BOOST_AUTO_TEST_SUITE_END() |