From 026bbfaf2b5d73a26b8e2fa49158883ef64c211b Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期四, 27 五月 2021 13:51:26 +0800 Subject: [PATCH] tcp server call center to send proxy requests. --- box/tcp_server.cpp | 32 +++++--------------------------- 1 files changed, 5 insertions(+), 27 deletions(-) diff --git a/box/tcp_server.cpp b/box/tcp_server.cpp index e4e229c..ea23106 100644 --- a/box/tcp_server.cpp +++ b/box/tcp_server.cpp @@ -23,39 +23,17 @@ using namespace std::chrono_literals; -TcpServer::TcpServer(int port) : - run_(false), listener_(io_, tcp::endpoint(tcp::v6(), port)) +TcpServer::TcpServer(int port, CenterPtr pscenter) : + listener_(io(), tcp::endpoint(tcp::v6(), port)), pscenter_(pscenter) { Accept(); } TcpServer::~TcpServer() { Stop(); } -bool TcpServer::Start() +void TcpServer::OnStop() { - Stop(); - bool cur = false; - if (run_.compare_exchange_strong(cur, true)) { - auto proc = [this]() { - while (run_) { - io_.run_one_for(100ms); - } - }; - std::thread(proc).swap(worker_); - } -} -void TcpServer::Stop() -{ - bool cur = true; - if (run_.compare_exchange_strong(cur, false)) { - io_.post([this]() { - listener_.close(); - }); - std::this_thread::sleep_for(1s); - if (worker_.joinable()) { - worker_.join(); - } - } + listener_.close(); } void TcpServer::Accept() @@ -63,7 +41,7 @@ listener_.async_accept([this](bserror_t ec, tcp::socket sock) { if (!ec) { LOG_INFO() << "server accept client"; - TcpReply1::Create(std::move(sock)); + TcpReply1::Create(std::move(sock), pscenter_); } Accept(); }); -- Gitblit v1.8.0