From b59cd08901baa81f1c2fe3c625ce89ca35e92990 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Tue, 7 Nov 2017 13:41:59 +0100 Subject: [PATCH] additonal fix for GH #1212: WebSocketImpl::available() now reports number of bytes in internal buffer. --- Net/src/WebSocketImpl.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Net/src/WebSocketImpl.cpp b/Net/src/WebSocketImpl.cpp index b3eb4c580..551671e69 100644 --- a/Net/src/WebSocketImpl.cpp +++ b/Net/src/WebSocketImpl.cpp @@ -55,13 +55,13 @@ WebSocketImpl::~WebSocketImpl() } } - + int WebSocketImpl::sendBytes(const void* buffer, int length, int flags) { Poco::Buffer frame(length + MAX_HEADER_LENGTH); Poco::MemoryOutputStream ostr(frame.begin(), frame.size()); Poco::BinaryWriter writer(ostr, Poco::BinaryWriter::NETWORK_BYTE_ORDER); - + if (flags == 0) flags = WebSocket::FRAME_BINARY; flags &= 0xff; writer << static_cast(flags); @@ -105,7 +105,7 @@ int WebSocketImpl::sendBytes(const void* buffer, int length, int flags) return length; } - + int WebSocketImpl::receiveHeader(char mask[4], bool& useMask) { char header[MAX_HEADER_LENGTH]; @@ -318,7 +318,7 @@ void WebSocketImpl::shutdownSend() _pStreamSocketImpl->shutdownSend(); } - + void WebSocketImpl::shutdown() { _pStreamSocketImpl->shutdown(); @@ -375,8 +375,12 @@ Poco::Timespan WebSocketImpl::getReceiveTimeout() int WebSocketImpl::available() { - return _pStreamSocketImpl->available(); + int n = _buffer.size() - _bufferOffset; + if (n > 0) + return n; + else + return _pStreamSocketImpl->available(); } - + } } // namespace Poco::Net