diff --git a/server/mymangosd/app.cc b/server/mymangosd/app.cc index 5b40301..c9e1dbb 100644 --- a/server/mymangosd/app.cc +++ b/server/mymangosd/app.cc @@ -9,7 +9,7 @@ App::App() const std::string App::GetPkgName() { - return ""; + return "mangosd"; } void App::Init() diff --git a/third_party/f8/f8/iomgr.h b/third_party/f8/f8/iomgr.h index d5603b7..88cad8c 100644 --- a/third_party/f8/f8/iomgr.h +++ b/third_party/f8/f8/iomgr.h @@ -21,6 +21,7 @@ namespace f8 private: std::vector>> io_works_; std::vector>> io_contexts_; + friend class TcpClient; }; } diff --git a/third_party/f8/f8/tcpclient.cc b/third_party/f8/f8/tcpclient.cc index f939109..28520f3 100644 --- a/third_party/f8/f8/tcpclient.cc +++ b/third_party/f8/f8/tcpclient.cc @@ -4,13 +4,28 @@ #include #include +#include const int MAX_RECV_BUFFERSIZE = 1024 * 64; namespace f8 { - TcpClient::TcpClient(std::shared_ptr io_context, const std::string& remote_ip, int remote_port) + TcpClient::TcpClient(std::shared_ptr io_context, + const std::string& remote_ip, + int remote_port) + { + Init(io_context, remote_ip, remote_port); + } + + TcpClient::TcpClient(const std::string& remote_ip, int remote_port) + { + Init(f8::IoMgr::Instance()->GetIoContext(0), remote_ip, remote_port); + } + + void TcpClient::Init(std::shared_ptr io_context, + const std::string& remote_ip, + int remote_port) { io_context_ = io_context; remote_address_ = remote_ip; @@ -18,7 +33,7 @@ namespace f8 endpoint_ = std::make_shared ( asio::ip::address::from_string(remote_address_), - remote_port_ + remote_port_ ); send_buffer_mutex_ = std::make_shared(); socket_ = std::make_shared(*io_context); diff --git a/third_party/f8/f8/tcpclient.h b/third_party/f8/f8/tcpclient.h index c7bcf29..734089c 100644 --- a/third_party/f8/f8/tcpclient.h +++ b/third_party/f8/f8/tcpclient.h @@ -14,9 +14,11 @@ namespace f8 std::function on_connect; std::function on_disconnect; std::function on_socketread; + TcpClient(std::shared_ptr io_context, - const std::string& remote_ip, - int remote_port); + const std::string& remote_ip, + int remote_port); + TcpClient(const std::string& remote_ip, int remote_port); virtual ~TcpClient(); const std::string& GetRemoteAddress() { return remote_address_; } int GetRemotePort() { return remote_port_; } @@ -28,6 +30,9 @@ namespace f8 void SendBuff(const char* buff, unsigned int bufflen); private: + void Init(std::shared_ptr io_context, + const std::string& remote_ip, + int remote_port); void HandleConnect(const asio::error_code& err); void DoRead(); void DoSend();