diff options
author | 2016-03-02 11:05:51 +0200 | |
---|---|---|
committer | 2016-03-02 13:35:09 +0200 | |
commit | 59a3b58d240661a2bc06c6ede473d2eda4eb5e55 (patch) | |
tree | 37dd8d43c4bc6a0421d5964d7d1c57be3cca51a2 /src/rpc-server | |
parent | 70cfb9f88b00016f1413754e5625b5b05acc2063 (diff) |
TX barrier
Diffstat (limited to 'src/rpc-server')
-rw-r--r-- | src/rpc-server/trex_rpc_req_resp_server.cpp | 35 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_req_resp_server.h | 2 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_server.cpp | 32 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_server_api.h | 2 |
4 files changed, 32 insertions, 39 deletions
diff --git a/src/rpc-server/trex_rpc_req_resp_server.cpp b/src/rpc-server/trex_rpc_req_resp_server.cpp index da7e8c55..5c587e0f 100644 --- a/src/rpc-server/trex_rpc_req_resp_server.cpp +++ b/src/rpc-server/trex_rpc_req_resp_server.cpp @@ -173,10 +173,8 @@ void TrexRpcServerReqRes::process_request_raw(const std::string &request, std::s int index = 0; - /* if lock was provided, take it */ - if (m_lock) { - m_lock->lock(); - } + /* expcetion safe */ + std::unique_lock<std::mutex> lock(*m_lock); /* for every command parsed - launch it */ for (auto command : commands) { @@ -190,9 +188,7 @@ void TrexRpcServerReqRes::process_request_raw(const std::string &request, std::s } /* done with the lock */ - if (m_lock) { - m_lock->unlock(); - } + lock.unlock(); /* write the JSON to string and sever on ZMQ */ @@ -254,28 +250,3 @@ TrexRpcServerReqRes::test_inject_request(const std::string &req) { return response; } - -/** - * MOCK req resp server - */ -TrexRpcServerReqResMock::TrexRpcServerReqResMock(const TrexRpcServerConfig &cfg) : TrexRpcServerReqRes(cfg) { -} - -/** - * override start - * - */ -void -TrexRpcServerReqResMock::start() { - -} - - -/** - * override stop - */ -void -TrexRpcServerReqResMock::stop() { - -} - diff --git a/src/rpc-server/trex_rpc_req_resp_server.h b/src/rpc-server/trex_rpc_req_resp_server.h index 979bf9af..26b3248f 100644 --- a/src/rpc-server/trex_rpc_req_resp_server.h +++ b/src/rpc-server/trex_rpc_req_resp_server.h @@ -55,7 +55,6 @@ protected: void *m_socket; }; - /** * a mock req resp server (for tests) * @@ -73,5 +72,6 @@ public: }; + #endif /* __TREX_RPC_REQ_RESP_API_H__ */ diff --git a/src/rpc-server/trex_rpc_server.cpp b/src/rpc-server/trex_rpc_server.cpp index 1dfc4494..7d2e31a5 100644 --- a/src/rpc-server/trex_rpc_server.cpp +++ b/src/rpc-server/trex_rpc_server.cpp @@ -33,6 +33,9 @@ limitations under the License. TrexRpcServerInterface::TrexRpcServerInterface(const TrexRpcServerConfig &cfg, const std::string &name, std::mutex *lock) : m_cfg(cfg), m_name(name), m_lock(lock) { m_is_running = false; m_is_verbose = false; + if (m_lock == NULL) { + m_lock = &m_dummy_lock; + } } TrexRpcServerInterface::~TrexRpcServerInterface() { @@ -117,7 +120,6 @@ get_current_date_time() { const std::string TrexRpcServer::s_server_uptime = get_current_date_time(); TrexRpcServer::TrexRpcServer(const TrexRpcServerConfig *req_resp_cfg, - const TrexRpcServerConfig *async_cfg, std::mutex *lock) { m_req_resp = NULL; @@ -134,10 +136,6 @@ TrexRpcServer::TrexRpcServer(const TrexRpcServerConfig *req_resp_cfg, m_servers.push_back(m_req_resp); } - /* add async publisher */ - if (async_cfg) { - m_servers.push_back(new TrexRpcServerAsync(*async_cfg, lock)); - } } TrexRpcServer::~TrexRpcServer() { @@ -187,3 +185,27 @@ TrexRpcServer::test_inject_request(const std::string &req_str) { return ""; } } + +/** + * MOCK req resp server + */ +TrexRpcServerReqResMock::TrexRpcServerReqResMock(const TrexRpcServerConfig &cfg) : TrexRpcServerReqRes(cfg) { +} + +/** + * override start + * + */ +void +TrexRpcServerReqResMock::start() { + +} + + +/** + * override stop + */ +void +TrexRpcServerReqResMock::stop() { + +} diff --git a/src/rpc-server/trex_rpc_server_api.h b/src/rpc-server/trex_rpc_server_api.h index 1ab5dce9..a02b2cc0 100644 --- a/src/rpc-server/trex_rpc_server_api.h +++ b/src/rpc-server/trex_rpc_server_api.h @@ -133,6 +133,7 @@ protected: std::thread *m_thread; std::string m_name; std::mutex *m_lock; + std::mutex m_dummy_lock; }; /** @@ -147,7 +148,6 @@ public: /* creates the collection of servers using configurations */ TrexRpcServer(const TrexRpcServerConfig *req_resp_cfg, - const TrexRpcServerConfig *async_cfg, std::mutex *m_lock = NULL); ~TrexRpcServer(); |