Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.

Commit

Permalink
clean code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gogs committed Jun 2, 2016
1 parent 20da399 commit ca39c6b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
1 change: 1 addition & 0 deletions connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <boost/asio.hpp>
#include <boost/asio/deadline_timer.hpp>
#include "common.h"
#include "router.hpp"

using boost::asio::ip::tcp;

Expand Down
16 changes: 5 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
#include <iostream>
#include <string>
#include <tuple>
#include <fstream>
#include <kapok/Kapok.hpp>
#include <boost/timer.hpp>
#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)
{
Expand All @@ -26,7 +17,7 @@ struct messager
}
};

TEST_CASE(rpc_qps, true)
int main()
{
messager m;
log::get().init("rest_rpc_server.lg");
Expand All @@ -35,4 +26,7 @@ TEST_CASE(rpc_qps, true)
s.register_handler("translate", &messager::translate, &m);

s.run();

getchar();
return 0;
}
8 changes: 4 additions & 4 deletions server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mtx_);

auto range = conn_map_.equal_range(topic);
Expand All @@ -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();
Expand All @@ -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
Expand Down Expand Up @@ -146,14 +147,13 @@ class server : private boost::noncopyable
#endif
}

//insert
std::multimap<std::string, std::weak_ptr<connection>> conn_map_;
io_service_pool io_service_pool_;
tcp::acceptor acceptor_;
std::shared_ptr<connection> conn_;
std::shared_ptr<std::thread> thd_;
std::size_t timeout_milli_;
#ifdef PUB_SUB
std::multimap<std::string, std::weak_ptr<connection>> conn_map_;
std::mutex mtx_;
#endif
};
Expand Down

0 comments on commit ca39c6b

Please sign in to comment.