Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
High watermark callback should only stop reading peer connection if its output buffer is not empty. Originally, the high watermark callback will stop reading the peer connection and register a write complete callback unconditionally. Consiter two events happening in the same EventLoop iteration: Connection C is readable Connection S is writable In C.onMessage(), it calls S.send(), then decides to queue a high watermark callback because S.outputBuffer is full. S.HWM will be called after event handling. In S.handleWrite(), all data are sent, output buffer becomes empty, but it doesn't queue write complete callback of S because it's not registered yet. In doPendingFunctors(), S.HWM is called, stop reading C, and register a write complete callback for S to re-enable reading C. This will never happen because S has nothing to send, it is already write complete. A false fix: Register write complete callback at beginning, never unregister it. This of course has some performance penalty, but appears to work because in the case of two events above, S.handleWrite() will queue its write complete callback after S.HWM. In doPendingFunctors(), first call S.HWM to stop reading C, then call S.WC to re-enable reading C. This false fix has a subtle dependency on the execution sequence of muduo EventLoop::doPendingFunctors(), and if EventLoop replace the queue with a stack, the program breaks mystically.
- Loading branch information