diff --git a/server/wsproxy/upstream.cc b/server/wsproxy/upstream.cc index d56036b..bc7dce7 100644 --- a/server/wsproxy/upstream.cc +++ b/server/wsproxy/upstream.cc @@ -2,7 +2,11 @@ #include +#ifdef USE_ASIO +#include +#else #include +#endif #include #include @@ -16,12 +20,6 @@ const int PACK_MAX = 1024 * 64 * 2; -#ifdef USE_ASIO -UpStream::UpStream(asio::io_context& io_context):socket_(io_context) -{ -} -#endif - void UpStream::Init(int instance_id, const std::string& remote_ip, int remote_port) { if (remote_ip.empty()) { @@ -34,7 +32,11 @@ void UpStream::Init(int instance_id, const std::string& remote_ip, int remote_po recv_bufflen_ = 0; last_pong_tick = a8::XGetTickCount(); recv_buff_ = (char*) malloc(PACK_MAX * 2); +#ifdef USE_ASIO + tcp_client_ = std::make_shared(); +#else tcp_client_ = std::make_shared(); +#endif tcp_client_->remote_address = remote_ip; tcp_client_->remote_port = remote_port; tcp_client_->on_error = std::bind(&UpStream::on_error, this, std::placeholders::_1, std::placeholders::_2); @@ -154,7 +156,11 @@ void UpStream::ForwardClientMsgEx(f8::MsgHdr* hdr) } } +#ifdef USE_ASIO +void UpStream::on_error(a8::AsioTcpClient* sender, int errorId) +#else void UpStream::on_error(a8::TcpClient* sender, int errorId) +#endif { f8::UdpLog::Instance()->Error("target server errorid=%d remote_ip:%s remote_port:%d", { @@ -164,7 +170,11 @@ void UpStream::on_error(a8::TcpClient* sender, int errorId) }); } +#ifdef USE_ASIO +void UpStream::on_connect(a8::AsioTcpClient* sender) +#else void UpStream::on_connect(a8::TcpClient* sender) +#endif { recv_bufflen_ = 0; f8::UdpLog::Instance()->Info("target server connected remote_ip:%s remote_port:%d", @@ -184,7 +194,11 @@ void UpStream::on_connect(a8::TcpClient* sender) ); } +#ifdef USE_ASIO +void UpStream::on_disconnect(a8::AsioTcpClient* sender) +#else void UpStream::on_disconnect(a8::TcpClient* sender) +#endif { recv_bufflen_ = 0; f8::UdpLog::Instance()->Info("target server %d disconnected after 10s later reconnect " @@ -206,7 +220,11 @@ void UpStream::on_disconnect(a8::TcpClient* sender) ); } +#ifdef USE_ASIO +void UpStream::on_socketread(a8::AsioTcpClient* sender, char* buf, unsigned int len) +#else void UpStream::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len) +#endif { #if 0 ++App::Instance()->perf.read_count; diff --git a/server/wsproxy/upstream.h b/server/wsproxy/upstream.h index b03a3d9..dca63a6 100644 --- a/server/wsproxy/upstream.h +++ b/server/wsproxy/upstream.h @@ -2,13 +2,10 @@ #include -#ifdef USE_ASIO -#include -#endif - namespace a8 { class TcpClient; + class AsioTcpClient; } struct UpStreamMsgNode @@ -30,9 +27,6 @@ class UpStream a8::tick_t last_pong_tick = 0; public: -#ifdef USE_ASIO - UpStream(asio::io_context& io_context); -#endif void Init(int instance_id, const std::string& remote_ip, int remote_port); void UnInit(); @@ -62,10 +56,17 @@ class UpStream void ForwardClientMsgEx(f8::MsgHdr* hdr); private: +#ifdef USE_ASIO + void on_error(a8::AsioTcpClient* sender, int errorId); + void on_connect(a8::AsioTcpClient* sender); + void on_disconnect(a8::AsioTcpClient* sender); + void on_socketread(a8::AsioTcpClient* sender, char* buf, unsigned int len); +#else void on_error(a8::TcpClient* sender, int errorId); void on_connect(a8::TcpClient* sender); void on_disconnect(a8::TcpClient* sender); void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len); +#endif void CheckAlive(); void AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg, @@ -74,9 +75,10 @@ class UpStream private: char *recv_buff_ = nullptr; unsigned int recv_bufflen_ = 0; - std::shared_ptr tcp_client_; #ifdef USE_ASIO - asio::ip::tcp::socket socket_; + std::shared_ptr tcp_client_; +#else + std::shared_ptr tcp_client_; #endif f8::TimerWp timer_wp_; f8::Attacher attacher_; diff --git a/server/wsproxy/upstreammgr.cc b/server/wsproxy/upstreammgr.cc index 2f05427..f1c455b 100644 --- a/server/wsproxy/upstreammgr.cc +++ b/server/wsproxy/upstreammgr.cc @@ -55,12 +55,7 @@ std::weak_ptr UpStreamMgr::RecreateUpStream(const std::string& host, i int instance_id = curr_id_; std::string remote_ip = host; int remote_port = port; -#ifdef USE_ASIO - asio::io_context io_context; - std::shared_ptr conn = std::make_shared(io_context); -#else std::shared_ptr conn = std::make_shared(); -#endif conn->Init(instance_id, remote_ip, remote_port); id_hash_[conn->instance_id] = conn; key_hash_[key] = conn; diff --git a/third_party/a8 b/third_party/a8 index 54fe50e..c5e180a 160000 --- a/third_party/a8 +++ b/third_party/a8 @@ -1 +1 @@ -Subproject commit 54fe50edf11dda774dcd6fc480134c9e4ce449cd +Subproject commit c5e180a96a7ba0d89f41f28821b0eb081f7ee880 diff --git a/third_party/f8 b/third_party/f8 index ae5c84a..e8e6a85 160000 --- a/third_party/f8 +++ b/third_party/f8 @@ -1 +1 @@ -Subproject commit ae5c84ae98a314a6f29a2e29e9a2937801324c15 +Subproject commit e8e6a85b8f00a248eea7aea80276c6f1afd98ef9