From cf2fa33fe0d73f7001d262beee5e8aba03544126 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 30 Jan 2016 00:17:54 +0900 Subject: WinTLS: Fix hang because of buffered received data WinTLSSession buffers received decrypted data into its own buffer. If read is requested, it copies the data from its buffer. But if requested buffer size is less than decrypted buffer, some of the data is left in the buffer. Previously, we had no facility to check the existence of this pending data. If this data is the last requested data from remote server, we may end up waiting for read event even if we have already data in our buffer, which may cause hang. This commit fixes this issue by introducing function to return the buffered length in TLSSession. SocketCore also provides the same function, which delegates to TLSSession object. --- src/HttpServerCommand.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/HttpServerCommand.cc') diff --git a/src/HttpServerCommand.cc b/src/HttpServerCommand.cc index 8ce196df..f39d2fab 100644 --- a/src/HttpServerCommand.cc +++ b/src/HttpServerCommand.cc @@ -107,10 +107,13 @@ HttpServerCommand::~HttpServerCommand() void HttpServerCommand::checkSocketRecvBuffer() { - if (!httpServer_->getSocketRecvBuffer()->bufferEmpty()) { - setStatus(Command::STATUS_ONESHOT_REALTIME); - e_->setNoWait(true); + if (httpServer_->getSocketRecvBuffer()->bufferEmpty() && + socket_->getRecvBufferedLength() == 0) { + return; } + + setStatus(Command::STATUS_ONESHOT_REALTIME); + e_->setNoWait(true); } #ifdef ENABLE_WEBSOCKET @@ -172,6 +175,7 @@ bool HttpServerCommand::execute() } try { if (socket_->isReadable(0) || (writeCheck_ && socket_->isWritable(0)) || + socket_->getRecvBufferedLength() || !httpServer_->getSocketRecvBuffer()->bufferEmpty()) { timeoutTimer_ = global::wallclock(); -- cgit