diff --git a/a8/tcpsession2.cc b/a8/tcpsession2.cc index 71cfd87..2b0ddc2 100644 --- a/a8/tcpsession2.cc +++ b/a8/tcpsession2.cc @@ -89,6 +89,7 @@ namespace a8 top_node_ = p; bot_node_ = p; } + NotifyEpollSend(); } else { if (work_node_) { abort(); @@ -101,6 +102,7 @@ namespace a8 case 0: case -2: { + assert(ret == 0); if (p->buff) { free(p->buff); } @@ -320,7 +322,8 @@ namespace a8 work_node_->bufflen - work_node_->sent_bytes, 0); if (sentbytes <= 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { + auto err_code = errno; + if (err_code == EAGAIN || err_code == EWOULDBLOCK) { break; } else { abort(); @@ -357,30 +360,32 @@ namespace a8 sending_ = true; struct epoll_event ev; ev.data.fd = socket_; - ev.events = EPOLLIN | EPOLLOUT | EPOLLET | EPOLLRDHUP; + ev.events = EPOLLIN | EPOLLET | EPOLLOUT | EPOLLRDHUP; ev.data.ptr = this; ::epoll_ctl(epoll_fd, EPOLL_CTL_MOD, socket_, &ev); } int TcpSession::DirectSend(a8::SendQueueNode* p) { - int sentbytes = ::send(socket_, - p->buff, - p->bufflen, - 0); - if (sentbytes >= p->bufflen) { - return 0; - } - if (sentbytes <= 0) { - if (errno == EAGAIN || errno == EWOULDBLOCK) { - return -1; + ++direct_send_times; + while (true) { + int sentbytes = ::send(socket_, + p->buff + p->sent_bytes, + p->bufflen - p->sent_bytes, + 0); + if (sentbytes <= 0) { + if (errno == EAGAIN || errno == EWOULDBLOCK) { + return -1; + } else { + Close(); + return -2; + } } else { - Close(); - return -2; + p->sent_bytes += sentbytes; + if (p->sent_bytes >= p->bufflen) { + return 0; + } } - } else { - p->sent_bytes += sentbytes; - return -1; } } diff --git a/a8/tcpsession2.h b/a8/tcpsession2.h index 45e75a9..2811da1 100644 --- a/a8/tcpsession2.h +++ b/a8/tcpsession2.h @@ -62,6 +62,7 @@ namespace a8 int max_packet_len_ = 0; volatile long long epoll_out_times = 0; volatile long long epoll_in_times = 0; + volatile long long direct_send_times = 0; private: int socket_ = 0;