diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-10-10 10:30:11 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-10-10 10:30:11 +0200 |
commit | 5b410d7d1f398272cef6a031b561377bed3694f7 (patch) | |
tree | b55f87562d553f67d21728b885a31fdfb336d19b /src | |
parent | e2e1a0f374aeffc933d0e5d295607197d6b74a4a (diff) | |
download | dabmux-5b410d7d1f398272cef6a031b561377bed3694f7.tar.gz dabmux-5b410d7d1f398272cef6a031b561377bed3694f7.tar.bz2 dabmux-5b410d7d1f398272cef6a031b561377bed3694f7.zip |
Replace m_running by m_active in RC
Diffstat (limited to 'src')
-rw-r--r-- | src/RemoteControl.cpp | 15 | ||||
-rw-r--r-- | src/RemoteControl.h | 18 |
2 files changed, 18 insertions, 15 deletions
diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp index 9ee1f24..305334b 100644 --- a/src/RemoteControl.cpp +++ b/src/RemoteControl.cpp @@ -85,13 +85,13 @@ void RemoteControllers::set_param( // thread. void RemoteControllerTelnet::restart_thread(long) { - m_running = false; - if (m_port) { m_child_thread.interrupt(); m_child_thread.join(); } + m_fault = false; + m_child_thread = boost::thread(&RemoteControllerTelnet::process, this, 0); } @@ -110,7 +110,7 @@ void RemoteControllerTelnet::process(long) tcp::acceptor acceptor(io_service, tcp::endpoint( boost::asio::ip::address::from_string("127.0.0.1"), m_port) ); - while (m_running) { + while (m_active) { in_message = ""; tcp::socket socket(io_service); @@ -123,7 +123,7 @@ void RemoteControllerTelnet::process(long) boost::asio::transfer_all(), ignored_error); - while (m_running && in_message != "quit") { + while (m_active && in_message != "quit") { boost::asio::write(socket, boost::asio::buffer(m_prompt), boost::asio::transfer_all(), ignored_error); @@ -160,7 +160,8 @@ void RemoteControllerTelnet::process(long) } } catch (std::exception& e) { - std::cerr << "Remote control caught exception: " << e.what() << std::endl; + etiLog.level(error) << + "Remote control caught exception: " << e.what(); m_fault = true; } } @@ -293,7 +294,7 @@ void RemoteControllerZmq::restart() // thread. void RemoteControllerZmq::restart_thread() { - m_running = false; + m_active = false; if (!m_endpoint.empty()) { m_child_thread.interrupt(); @@ -352,7 +353,7 @@ void RemoteControllerZmq::process() // create pollitem that polls the ZMQ sockets zmq::pollitem_t pollItems[] = { {repSocket, 0, ZMQ_POLLIN, 0} }; - for (;;) { + while (m_active) { zmq::poll(pollItems, 1, 100); std::vector<std::string> msg; diff --git a/src/RemoteControl.h b/src/RemoteControl.h index 1a81b42..da6f9ea 100644 --- a/src/RemoteControl.h +++ b/src/RemoteControl.h @@ -198,11 +198,11 @@ extern RemoteControllers rcs; class RemoteControllerTelnet : public BaseRemoteController { public: RemoteControllerTelnet() - : m_running(false), m_fault(false), + : m_active(false), m_fault(false), m_port(0) { } RemoteControllerTelnet(int port) - : m_running(true), m_fault(false), + : m_active(port > 0), m_fault(false), m_child_thread(&RemoteControllerTelnet::process, this, 0), m_port(port) { } @@ -210,7 +210,7 @@ class RemoteControllerTelnet : public BaseRemoteController { RemoteControllerTelnet(const RemoteControllerTelnet& other) = delete; ~RemoteControllerTelnet() { - m_running = false; + m_active = false; m_fault = false; if (m_port) { m_child_thread.interrupt(); @@ -243,7 +243,7 @@ class RemoteControllerTelnet : public BaseRemoteController { return all_tokens; } - std::atomic<bool> m_running; + std::atomic<bool> m_active; /* This is set to true if a fault occurred */ std::atomic<bool> m_fault; @@ -261,12 +261,12 @@ class RemoteControllerTelnet : public BaseRemoteController { class RemoteControllerZmq : public BaseRemoteController { public: RemoteControllerZmq() - : m_running(false), m_fault(false), + : m_active(false), m_fault(false), m_zmqContext(1), m_endpoint("") { } RemoteControllerZmq(const std::string& endpoint) - : m_running(true), m_fault(false), + : m_active(not endpoint.empty()), m_fault(false), m_zmqContext(1), m_endpoint(endpoint), m_child_thread(&RemoteControllerZmq::process, this) { } @@ -275,8 +275,10 @@ class RemoteControllerZmq : public BaseRemoteController { RemoteControllerZmq(const RemoteControllerZmq& other) = delete; ~RemoteControllerZmq() { - m_running = false; + m_active = false; m_fault = false; + + m_zmqContext.close(); if (!m_endpoint.empty()) { m_child_thread.interrupt(); m_child_thread.join(); @@ -295,7 +297,7 @@ class RemoteControllerZmq : public BaseRemoteController { void send_fail_reply(zmq::socket_t &pSocket, const std::string &error); void process(); - std::atomic<bool> m_running; + std::atomic<bool> m_active; /* This is set to true if a fault occurred */ std::atomic<bool> m_fault; |