Skip to content

Commit

Permalink
更正epoll.cc中sendRes的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
linanwx committed May 14, 2018
1 parent 7793dde commit b3fd021
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions raw-examples/epoll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ map<int, Con> cons;
string httpRes;
void sendRes(int efd, int fd) {
Con& con = cons[fd];
if (!con.readed.length()) {
if (con.writeEnabled) {
updateEvents(efd, fd, EPOLLIN, EPOLL_CTL_MOD);
con.writeEnabled = false;
}
return;
}
size_t left = httpRes.length() - con.written;
int wd = 0;
while((wd=::write(fd, httpRes.data()+con.written, left))>0) {
Expand All @@ -81,6 +74,10 @@ void sendRes(int efd, int fd) {
};
if (left == 0) {
// close(fd); // 测试中使用了keepalive,因此不关闭连接。连接会在read事件中关闭
if (con.writeEnabled) {
updateEvents(efd, fd, EPOLLIN, EPOLL_CTL_MOD); // 当所有数据发送结束后,不再关注其缓冲区可写事件
con.writeEnabled = false;
}
cons.erase(fd);
return;
}
Expand Down

0 comments on commit b3fd021

Please sign in to comment.