diff --git a/third_party/f8/f8/internal/asiotcpclient.cc b/third_party/f8/f8/internal/asiotcpclient.cc index bbd2152..7022dd0 100644 --- a/third_party/f8/f8/internal/asiotcpclient.cc +++ b/third_party/f8/f8/internal/asiotcpclient.cc @@ -71,7 +71,7 @@ namespace f8 return connected_; } - void AsioTcpClient::SendBuff(const char* buff, unsigned int bufflen) + void AsioTcpClient::SendBuff(const char* buff, int bufflen) { //a8::XPrintf("SendBuff bufflen:%d\n", {bufflen}); if (bufflen > 0) { @@ -149,8 +149,8 @@ namespace f8 [this](std::error_code ec, std::size_t bytes_transferred) { if (!ec) { - if (on_socketread) { - on_socketread(this, buffer_.data(), bytes_transferred); + if (on_read) { + on_read(this, buffer_.data(), bytes_transferred); } DoRead(); } else { @@ -214,4 +214,5 @@ asio::buffer(buf, buf_len), } } + } diff --git a/third_party/f8/f8/internal/asiotcpclient.h b/third_party/f8/f8/internal/asiotcpclient.h index 2a44f81..64a4339 100644 --- a/third_party/f8/f8/internal/asiotcpclient.h +++ b/third_party/f8/f8/internal/asiotcpclient.h @@ -15,7 +15,7 @@ namespace f8 std::function on_error; std::function on_connect; std::function on_disconnect; - std::function on_socketread; + std::function on_read; AsioTcpClient(std::shared_ptr io_context, const std::string& remote_ip, @@ -29,7 +29,7 @@ namespace f8 void Close(); bool IsActive(); bool Connected(); - void SendBuff(const char* buff, unsigned int bufflen); + void SendBuff(const char* buff, int bufflen); private: void Init(std::shared_ptr io_context, diff --git a/third_party/f8/f8/tcpclient.cc b/third_party/f8/f8/tcpclient.cc index 107d5c6..1159651 100644 --- a/third_party/f8/f8/tcpclient.cc +++ b/third_party/f8/f8/tcpclient.cc @@ -9,6 +9,34 @@ namespace f8 TcpClient::TcpClient(const std::string& remote_ip, int remote_port) { impl_ = std::make_shared(remote_ip, remote_port); + impl_->on_error = + [this] (f8::internal::AsioTcpClient*, int err_code) + { + if (on_error) { + on_error(this, err_code); + } + }; + impl_->on_connect = + [this] (f8::internal::AsioTcpClient*) + { + if (on_connect) { + on_connect(this); + } + }; + impl_->on_disconnect = + [this] (f8::internal::AsioTcpClient*, int err_code) + { + if (on_disconnect) { + on_disconnect(this, err_code); + } + }; + impl_->on_read = + [this] (f8::internal::AsioTcpClient*, char* buff, int buff_len) + { + if (on_read) { + on_read(this, buff, buff_len); + } + }; } TcpClient::~TcpClient() @@ -31,7 +59,7 @@ namespace f8 return impl_->Connected(); } - void TcpClient::SendBuff(const char* buff, unsigned int bufflen) + void TcpClient::SendBuff(const char* buff, int bufflen) { impl_->SendBuff(buff, bufflen); } diff --git a/third_party/f8/f8/tcpclient.h b/third_party/f8/f8/tcpclient.h index bc61d48..2cb492f 100644 --- a/third_party/f8/f8/tcpclient.h +++ b/third_party/f8/f8/tcpclient.h @@ -19,7 +19,7 @@ namespace f8 std::function on_error; std::function on_connect; std::function on_disconnect; - std::function on_socketread; + std::function on_read; TcpClient(const std::string& remote_ip, int remote_port); virtual ~TcpClient(); @@ -29,7 +29,7 @@ namespace f8 void Open(); void Close(); bool Connected(); - void SendBuff(const char* buff, unsigned int bufflen); + void SendBuff(const char* buff, int bufflen); private: std::shared_ptr impl_;