Skip to content

Commit

Permalink
Merge pull request #28 from Ashes110/27-add-check-pollhup-and-close-i…
Browse files Browse the repository at this point in the history
…f-it-is-true

Check POLLHUP and close client socket if it is true
  • Loading branch information
ShotaTanemura authored Jan 29, 2024
2 parents f0c2a15 + 5115be5 commit f29b4cb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/loop/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static bool setRevents(std::map<int, ServerSocket> &ssmap, std::map<int, ClientS
struct pollfd pfd;
std::memset(&pfd, 0, sizeof(struct pollfd));
pfd.fd = iter->first;
pfd.events = POLLIN | POLLOUT;
pfd.events = POLLIN | POLLOUT | POLLHUP;
pollfds.push_back(pfd);
}
if (poll(pollfds.data(), pollfds.size(), 0) == -1) {
Expand All @@ -45,6 +45,7 @@ static ClientSocket::csphase detectTimedOutClientSocket(ClientSocket &cs) {
if (std::difftime(std::time(NULL), cs.getLastSendTimestamp()) > 5) {
return ClientSocket::CLOSE;
}
if ((cs.getPhase() & POLLHUP) == POLLHUP) { return ClientSocket::CLOSE; }
return cs.getPhase();
}

Expand Down

0 comments on commit f29b4cb

Please sign in to comment.