From ca39c6b0ae6a3634ae1445215d113df30a284904 Mon Sep 17 00:00:00 2001 From: Gogs Date: Thu, 2 Jun 2016 15:49:19 +0800 Subject: [PATCH] clean code. --- connection.hpp | 1 + main.cpp | 16 +++++----------- server.hpp | 8 ++++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/connection.hpp b/connection.hpp index dde3a80..71a4855 100644 --- a/connection.hpp +++ b/connection.hpp @@ -4,6 +4,7 @@ #include #include #include "common.h" +#include "router.hpp" using boost::asio::ip::tcp; diff --git a/main.cpp b/main.cpp index 367c464..db4e9a6 100644 --- a/main.cpp +++ b/main.cpp @@ -1,15 +1,6 @@ -#include #include -#include -#include -#include -#include -#include "router.hpp" -#include "test_router.hpp" #include "server.hpp" -#include "base64.hpp" -#include "client_proxy/client_proxy.hpp" -#include "log.hpp" + int add(int a, int b) { @@ -26,7 +17,7 @@ struct messager } }; -TEST_CASE(rpc_qps, true) +int main() { messager m; log::get().init("rest_rpc_server.lg"); @@ -35,4 +26,7 @@ TEST_CASE(rpc_qps, true) s.register_handler("translate", &messager::translate, &m); s.run(); + + getchar(); + return 0; } \ No newline at end of file diff --git a/server.hpp b/server.hpp index 4cec819..a59ae78 100644 --- a/server.hpp +++ b/server.hpp @@ -76,8 +76,8 @@ class server : private boost::noncopyable void pub(const std::string& topic, const std::string& result) { - decltype(conn_map_.equal_range(topic)) temp; #ifdef PUB_SUB + decltype(conn_map_.equal_range(topic)) temp; std::unique_lock lock(mtx_); auto range = conn_map_.equal_range(topic); @@ -100,7 +100,7 @@ class server : private boost::noncopyable } lock.lock(); //clear invalid connection -#endif + for (auto it = conn_map_.cbegin(); it != conn_map_.end();) { auto ptr = it->second.lock(); @@ -113,6 +113,7 @@ class server : private boost::noncopyable ++it; } } +#endif } //this callback from router, tell the server which connection sub the topic and the result of handler @@ -146,14 +147,13 @@ class server : private boost::noncopyable #endif } - //insert - std::multimap> conn_map_; io_service_pool io_service_pool_; tcp::acceptor acceptor_; std::shared_ptr conn_; std::shared_ptr thd_; std::size_t timeout_milli_; #ifdef PUB_SUB + std::multimap> conn_map_; std::mutex mtx_; #endif };