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;
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;
}
}

View File

@ -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;