in case the total size of an incoming frame is smaller then MAX_HEADER_LENGTH (=14) - for example a single character in a text frame = 3 bytes in total -, AND successive frames are already queued in the receiving buffer, the current implementation of
- Code: Select all
int WebSocketImpl::receiveBytes(void* buffer, int length, int)
(my app is streaming alternating small text and large binary payloads)
i recommend a fix by introducing MIN_HEADER_SIZE(=2) constant, and modifying the beginning of receiveBytes() to:
- Code: Select all
int WebSocketImpl::receiveBytes(void* buffer, int length, int)
{
char header[MAX_HEADER_LENGTH];
int n = _pStreamSocketImpl->receiveBytes(header, MIN_HEADER_LENGTH);
Poco::UInt8 lengthByte = ((Poco::UInt8)header[1]) & 0x7f;
if( lengthByte+MIN_HEADER_LENGTH < MAX_HEADER_LENGTH )
n += _pStreamSocketImpl->receiveBytes(header + MIN_HEADER_LENGTH, lengthByte );
else
n += _pStreamSocketImpl->receiveBytes(header + MIN_HEADER_LENGTH, MAX_HEADER_LENGTH - MIN_HEADER_LENGTH);
if (n > 0)
{ //... the rest is unchanged
hope this helps some people. i also haven't checked for similar mechanics elsewhere, i'm sure the guys responsible for the websocket implementation will know where else to look...





