From b151dd7647dbcd4a863a4f0b67bb0527f0f880ab Mon Sep 17 00:00:00 2001 From: chenhaijian <2830005753@qq.com> Date: Thu, 25 Jul 2024 15:56:17 +0800 Subject: [PATCH] Add comments --- utils/TcpModule/src/TcpClientImpl.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/utils/TcpModule/src/TcpClientImpl.cpp b/utils/TcpModule/src/TcpClientImpl.cpp index fa3b5a3e..b2f27146 100644 --- a/utils/TcpModule/src/TcpClientImpl.cpp +++ b/utils/TcpModule/src/TcpClientImpl.cpp @@ -26,8 +26,8 @@ /** * @brief Called when data is received on a TCP connection. * - * @param io - * @param buf + * @param io Socket handle + * @param buf The transmitted data content * @param len */ static void on_message(hio_t *io, void *buf, int len) @@ -38,8 +38,7 @@ static void on_message(hio_t *io, void *buf, int len) } /** * @brief Called when TCP connection is established. - * - * @param io + * @param io Socket handle */ static void on_connect(hio_t *io) { @@ -47,6 +46,10 @@ static void on_connect(hio_t *io) hio_setcb_read(io, on_message); hio_read(io); } +/** + * @brief Called when tcp connection is disconnected. + * @param io Socket handle + */ static void on_close(hio_t *io) { LogInfo("onclose: connfd=%d error=%d\n", hio_fd(io), hio_error(io)); @@ -74,9 +77,9 @@ void TcpClientImpl::Init(void) return; } hevent_set_userdata(io, this); - hio_setcb_connect(io, on_connect); + hio_setcb_connect(io, on_connect);///Set the callback function of successful connection, and there is no connection operation. hio_setcb_close(io, on_close); - hio_connect(io); + hio_connect(io); ///Connection operation mIo = io; std::shared_ptr impl = std::dynamic_pointer_cast(shared_from_this()); auto recvThread = [](std::shared_ptr tcpClient) { @@ -114,7 +117,7 @@ ssize_t TcpClientImpl::Write(const void *buf, const size_t bufLenght) LogError("mIo is nullptr.\n"); return TCP_MODULE_WRITE_ERROR; } - return hio_write(mIo, buf, bufLenght); + return hio_write(mIo, buf, bufLenght); ///Returns the byte length of a packet.If it fails, an error code is returned. } void TcpClientImpl::Closed(void) {