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_proxy.cpp | 20 +++++--------------- 1 files changed, 5 insertions(+), 15 deletions(-) diff --git a/box/tcp_proxy.cpp b/box/tcp_proxy.cpp index 2e95a3b..298c6b6 100644 --- a/box/tcp_proxy.cpp +++ b/box/tcp_proxy.cpp @@ -36,8 +36,7 @@ auto localProc = [this](ShmSocket &sock, MsgI &msg, BHMsgHead &head) { auto &dest = head.dest(); if (dest.ip().empty() || dest.port() == 0) { return; } - bool r = Send(dest.ip(), dest.port(), msg.content()); - // TODO check send fail. + Request(dest.ip(), dest.port(), msg.content()); }; local_->Start(1, localProc); @@ -46,34 +45,25 @@ io_context_.run_one_for(std::chrono::milliseconds(100)); } }; + std::thread(proxyProc).swap(worker_); return true; } void TcpProxy::Stop() { - local_.reset(); - bool cur = true; if (run_.compare_exchange_strong(cur, false)) { if (worker_.joinable()) { worker_.join(); } + local_.reset(); } } -bool TcpProxy::Send(const std::string &ip, int port, std::string &&content) +bool TcpProxy::Request(const std::string &ip, int port, std::string &&content) { if (content.empty()) { return false; } tcp::endpoint dest(ip::address::from_string(ip), port); - TcpRequest1::Create(io_context_, dest, std::move(content)); - - // char tag[sizeof(kBHTcpServerTag)] = {0}; - - // int n = read(sock, tag, sizeof(tag)); - // if (n == sizeof(tag) && memcmp(tag, &kBHTcpServerTag, sizeof(tag)) == 0) { - // send(sock, content.data(), content.size(), 0); - // connections_[addr].io_info_.h_ = [this, sock](int events) { OnReply(sock); }; - // // success - // } + TcpRequest1::Create(io_context_, dest, std::move(content), *local_); } -- Gitblit v1.8.0