summaryrefslogtreecommitdiffstats
path: root/src/rpc-server
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-06-23 10:37:04 +0300
committerYaroslav Brustinov <ybrustin@cisco.com>2016-06-23 10:37:04 +0300
commitf2320939a5deec2db2948788479199931e1f9176 (patch)
treefc1b12908503d5b7d67cefe34e0c5fb0f908d2a6 /src/rpc-server
parent1eed7e59f23d3ab9b957d9822eefe72877e291da (diff)
parentd04442ab671f768a1b645fb887d4a9cd575c7852 (diff)
Merge branch 'master' into cpu_per_core
Conflicts: scripts/automation/trex_control_plane/server/singleton_daemon.py
Diffstat (limited to 'src/rpc-server')
-rw-r--r--src/rpc-server/trex_rpc_req_resp_server.cpp20
-rw-r--r--src/rpc-server/trex_rpc_server.cpp3
-rw-r--r--src/rpc-server/trex_rpc_server_api.h9
3 files changed, 14 insertions, 18 deletions
diff --git a/src/rpc-server/trex_rpc_req_resp_server.cpp b/src/rpc-server/trex_rpc_req_resp_server.cpp
index 033f265c..e0e7635c 100644
--- a/src/rpc-server/trex_rpc_req_resp_server.cpp
+++ b/src/rpc-server/trex_rpc_req_resp_server.cpp
@@ -56,7 +56,8 @@ void TrexRpcServerReqRes::_rpc_thread_cb() {
std::stringstream ss;
int zmq_rc;
- m_watchdog_handle = m_watchdog->register_monitor(m_name, 1);
+ m_monitor.create(m_name, 1);
+ TrexWatchDog::getInstance().register_monitor(&m_monitor);
/* create a socket based on the configuration */
@@ -102,7 +103,7 @@ void TrexRpcServerReqRes::_rpc_thread_cb() {
zmq_close(m_socket);
/* done */
- m_watchdog->disable_monitor(m_watchdog_handle);
+ m_monitor.disable();
}
bool
@@ -115,7 +116,7 @@ TrexRpcServerReqRes::fetch_one_request(std::string &msg) {
assert(rc == 0);
while (true) {
- m_watchdog->tickle(m_watchdog_handle);
+ m_monitor.tickle();
rc = zmq_msg_recv (&zmq_msg, m_socket, 0);
if (rc != -1) {
@@ -200,23 +201,24 @@ void TrexRpcServerReqRes::process_request_raw(const std::string &request, std::s
int index = 0;
- /* expcetion safe */
- std::unique_lock<std::mutex> lock(*m_lock);
-
/* for every command parsed - launch it */
for (auto command : commands) {
Json::Value single_response;
+ /* the command itself should be protected */
+ std::unique_lock<std::mutex> lock(*m_lock);
command->execute(single_response);
+ lock.unlock();
+
delete command;
response_json[index++] = single_response;
+ /* batch is like getting all the messages one by one - it should not be considered as stuck thread */
+ /* need to think if this is a good thing */
+ //m_monitor.tickle();
}
- /* done with the lock */
- lock.unlock();
-
/* write the JSON to string and sever on ZMQ */
if (response.size() == 1) {
diff --git a/src/rpc-server/trex_rpc_server.cpp b/src/rpc-server/trex_rpc_server.cpp
index e4ca95c3..6c323c16 100644
--- a/src/rpc-server/trex_rpc_server.cpp
+++ b/src/rpc-server/trex_rpc_server.cpp
@@ -36,8 +36,6 @@ TrexRpcServerInterface::TrexRpcServerInterface(const TrexRpcServerConfig &cfg, c
m_name = name;
m_lock = cfg.m_lock;
- m_watchdog = cfg.m_watchdog;
- m_watchdog_handle = -1;
m_is_running = false;
m_is_verbose = false;
@@ -78,7 +76,6 @@ void TrexRpcServerInterface::start() {
/* prepare for run */
_prepare();
- m_watchdog->mark_pending_monitor();
m_thread = new std::thread(&TrexRpcServerInterface::_rpc_thread_cb, this);
if (!m_thread) {
throw TrexRpcException("unable to create RPC thread");
diff --git a/src/rpc-server/trex_rpc_server_api.h b/src/rpc-server/trex_rpc_server_api.h
index 3d9837ef..6df37b17 100644
--- a/src/rpc-server/trex_rpc_server_api.h
+++ b/src/rpc-server/trex_rpc_server_api.h
@@ -30,10 +30,10 @@ limitations under the License.
#include <stdexcept>
#include <trex_rpc_exception_api.h>
#include <json/json.h>
+#include "trex_watchdog.h"
class TrexRpcServerInterface;
class TrexRpcServerReqRes;
-class TrexWatchDog;
/**
* defines a configuration of generic RPC server
@@ -48,11 +48,10 @@ public:
RPC_PROT_MOCK
};
- TrexRpcServerConfig(rpc_prot_e protocol, uint16_t port, std::mutex *lock, TrexWatchDog *watchdog) {
+ TrexRpcServerConfig(rpc_prot_e protocol, uint16_t port, std::mutex *lock) {
m_protocol = protocol;
m_port = port;
m_lock = lock;
- m_watchdog = watchdog;
}
uint16_t get_port() const {
@@ -69,7 +68,6 @@ private:
public:
std::mutex *m_lock;
- TrexWatchDog *m_watchdog;
};
/**
@@ -142,8 +140,7 @@ protected:
std::string m_name;
std::mutex *m_lock;
std::mutex m_dummy_lock;
- TrexWatchDog *m_watchdog;
- int m_watchdog_handle;
+ TrexMonitor m_monitor;
};
/**