Commit 5009c3cb authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Small simplification of AsyncSocket read loop

Summary: [Folly] Small simplification of `AsyncSocket` read loop.

Differential Revision: D21514325

fbshipit-source-id: 0af27205b4aa2807a800430e8a2b3dea36356970
parent fca66cf3
...@@ -1998,9 +1998,9 @@ void AsyncSocket::handleRead() noexcept { ...@@ -1998,9 +1998,9 @@ void AsyncSocket::handleRead() noexcept {
// AsyncSocket between threads properly. This will be sufficient to ensure // AsyncSocket between threads properly. This will be sufficient to ensure
// that this thread sees the updated eventBase_ variable after // that this thread sees the updated eventBase_ variable after
// readDataAvailable() returns.) // readDataAvailable() returns.)
uint16_t numReads = 0; size_t numReads = maxReadsPerEvent_ ? maxReadsPerEvent_ : size_t(-1);
EventBase* originalEventBase = eventBase_; EventBase* originalEventBase = eventBase_;
while (readCallback_ && eventBase_ == originalEventBase) { while (readCallback_ && eventBase_ == originalEventBase && numReads--) {
// Get the buffer to read into. // Get the buffer to read into.
void* buf = nullptr; void* buf = nullptr;
size_t buflen = 0, offset = 0; size_t buflen = 0, offset = 0;
...@@ -2077,15 +2077,12 @@ void AsyncSocket::handleRead() noexcept { ...@@ -2077,15 +2077,12 @@ void AsyncSocket::handleRead() noexcept {
callback->readEOF(); callback->readEOF();
return; return;
} }
if (maxReadsPerEvent_ && (++numReads >= maxReadsPerEvent_)) { }
if (readCallback_ != nullptr) { if (readCallback_ != nullptr) {
// We might still have data in the socket. // We might still have data in the socket.
// (e.g. see comment in AsyncSSLSocket::checkForImmediateRead) // (e.g. see comment in AsyncSSLSocket::checkForImmediateRead)
scheduleImmediateRead(); scheduleImmediateRead();
} }
return;
}
}
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment