优化asynctcpclient connect逻辑

This commit is contained in:
aozhiwei 2020-07-10 13:26:06 +08:00
parent 645913c9d4
commit d6786bcdb1

View File

@ -128,11 +128,25 @@ namespace a8
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();
}