This commit is contained in:
aozhiwei 2019-05-27 21:20:41 +08:00
parent fc4a7d7d24
commit f6748a84c8
2 changed files with 23 additions and 17 deletions

View File

@ -89,6 +89,7 @@ namespace a8
top_node_ = p; top_node_ = p;
bot_node_ = p; bot_node_ = p;
} }
NotifyEpollSend();
} else { } else {
if (work_node_) { if (work_node_) {
abort(); abort();
@ -101,6 +102,7 @@ namespace a8
case 0: case 0:
case -2: case -2:
{ {
assert(ret == 0);
if (p->buff) { if (p->buff) {
free(p->buff); free(p->buff);
} }
@ -320,7 +322,8 @@ namespace a8
work_node_->bufflen - work_node_->sent_bytes, work_node_->bufflen - work_node_->sent_bytes,
0); 0);
if (sentbytes <= 0) { if (sentbytes <= 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) { auto err_code = errno;
if (err_code == EAGAIN || err_code == EWOULDBLOCK) {
break; break;
} else { } else {
abort(); abort();
@ -357,20 +360,19 @@ namespace a8
sending_ = true; sending_ = true;
struct epoll_event ev; struct epoll_event ev;
ev.data.fd = socket_; ev.data.fd = socket_;
ev.events = EPOLLIN | EPOLLOUT | EPOLLET | EPOLLRDHUP; ev.events = EPOLLIN | EPOLLET | EPOLLOUT | EPOLLRDHUP;
ev.data.ptr = this; ev.data.ptr = this;
::epoll_ctl(epoll_fd, EPOLL_CTL_MOD, socket_, &ev); ::epoll_ctl(epoll_fd, EPOLL_CTL_MOD, socket_, &ev);
} }
int TcpSession::DirectSend(a8::SendQueueNode* p) int TcpSession::DirectSend(a8::SendQueueNode* p)
{ {
++direct_send_times;
while (true) {
int sentbytes = ::send(socket_, int sentbytes = ::send(socket_,
p->buff, p->buff + p->sent_bytes,
p->bufflen, p->bufflen - p->sent_bytes,
0); 0);
if (sentbytes >= p->bufflen) {
return 0;
}
if (sentbytes <= 0) { if (sentbytes <= 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) { if (errno == EAGAIN || errno == EWOULDBLOCK) {
return -1; return -1;
@ -380,7 +382,10 @@ namespace a8
} }
} else { } else {
p->sent_bytes += sentbytes; p->sent_bytes += sentbytes;
return -1; if (p->sent_bytes >= p->bufflen) {
return 0;
}
}
} }
} }

View File

@ -62,6 +62,7 @@ namespace a8
int max_packet_len_ = 0; int max_packet_len_ = 0;
volatile long long epoll_out_times = 0; volatile long long epoll_out_times = 0;
volatile long long epoll_in_times = 0; volatile long long epoll_in_times = 0;
volatile long long direct_send_times = 0;
private: private:
int socket_ = 0; int socket_ = 0;