diff options
author | Gyuhwan Park <unstabler@unstabler.pl> | 2022-05-28 11:30:20 +0300 |
---|---|---|
committer | Gyuhwan Park <unstabler@unstabler.pl> | 2022-05-28 11:30:20 +0300 |
commit | 0c5ffd7159b5f88878ec17d8bb19157aa960b1b6 (patch) | |
tree | 8a4e738a2ec05d11d161001576fdb99df26f5208 | |
parent | d3d534f7532b02db2d0ab20082cf1f9fa53c7dee (diff) |
fix(IPCConnection): do not break io loop even POLLHUP is set
-rw-r--r-- | IPCConnection.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/IPCConnection.cpp b/IPCConnection.cpp index b23f2e6..3da91c4 100644 --- a/IPCConnection.cpp +++ b/IPCConnection.cpp @@ -76,22 +76,19 @@ void IPCConnection::workerLoop() { size_t readPos = 0; std::unique_ptr<uint8_t> readBuffer; - pollfd pollFd; - pollFd.fd = _socket.descriptor(); - pollFd.events = POLLIN | POLLOUT; + pollfd pollFd { + _socket.descriptor(), + POLLIN | POLLOUT, + 0 + }; while (!_isWorkerTerminated) { if (poll(&pollFd, 1, 1) < 0) { throw SystemCallException(errno, "poll"); } - bool canRead = pollFd.revents & POLLIN; - bool canWrite = pollFd.revents & POLLOUT; - - if (pollFd.revents & (POLLERR | POLLHUP)) { - LOG(LOG_LEVEL_ERROR, "POLLERR | POLLHUP bit set; closing connection"); - break; - } + bool canRead = (pollFd.revents & POLLIN) > 0; + bool canWrite = (pollFd.revents & POLLOUT) > 0; if (canWrite && !_writeTasks.empty()) { auto writeTask = std::move(_writeTasks.front()); @@ -120,8 +117,6 @@ void IPCConnection::workerLoop() { readBuffer = std::unique_ptr<uint8_t>(new uint8_t[contentLength]); } - assert(sizeof readBuffer.get() == contentLength); - int readForBytes = std::min( (size_t) MAX_READ_SIZE, contentLength - readPos @@ -150,6 +145,14 @@ void IPCConnection::workerLoop() { readPos = 0; } } - + + if (pollFd.revents & POLLHUP) { + LOG(LOG_LEVEL_WARNING, "POLLHUP bit set"); + } + + if (pollFd.revents & POLLERR) { + LOG(LOG_LEVEL_ERROR, "POLLERR bit set; closing connection"); + break; + } } } |