From d6786bcdb167afad09bcad7d34e247879dfc735a Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 10 Jul 2020 13:26:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96asynctcpclient=20connect?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- a8/asynctcpclient.cc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/a8/asynctcpclient.cc b/a8/asynctcpclient.cc index e02bd0c..71502ba 100644 --- a/a8/asynctcpclient.cc +++ b/a8/asynctcpclient.cc @@ -125,14 +125,28 @@ namespace a8 void AsyncTcpClient::DoSend() { - if(socket_ == -1){ + if (socket_ == -1) { return; } + if (!work_node_) { + send_buffer_mutex_->lock(); + work_node_ = top_node_; + top_node_ = nullptr; + bot_node_ = nullptr; + send_buffer_mutex_->unlock(); + } if (!connected_) { int error = 0; socklen_t len = sizeof(error); ::getsockopt(socket_, SOL_SOCKET, SO_ERROR, &error, (socklen_t *)&len); if( !error ) { + if (!work_node_) { + struct epoll_event ev; + ev.data.fd = socket_; + ev.events = EPOLLIN | EPOLLRDHUP; + ev.data.ptr = this; + ::epoll_ctl(epoll_fd_, EPOLL_CTL_MOD, socket_, &ev); + } DoConnect(); } else { connected_ = false; @@ -148,13 +162,6 @@ namespace a8 return; } } - if (!work_node_) { - send_buffer_mutex_->lock(); - work_node_ = top_node_; - top_node_ = nullptr; - bot_node_ = nullptr; - send_buffer_mutex_->unlock(); - } if (work_node_) { AsyncSend(); }