Skip to content

Commit

Permalink
fix(Net): WebSocket: non-blocking receiveFrame()/receiveBytes() with …
Browse files Browse the repository at this point in the history
…TLS connection may get stuck receiving header #4850
  • Loading branch information
obiltschnig committed Jan 15, 2025
1 parent daf19e5 commit 705403d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Net/src/WebSocketImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,14 +464,27 @@ int WebSocketImpl::peekSomeBytes(char* buffer, int length)
std::memcpy(buffer, _buffer.begin() + _bufferOffset, n);
if (length > n)
{
int rc = _pStreamSocketImpl->receiveBytes(buffer + n, length - n, MSG_PEEK);
if (rc > 0) n += rc;
int rc = _pStreamSocketImpl->receiveBytes(buffer + n, length - n);
if (rc > 0)
{
std::size_t currentSize = _buffer.size();
_buffer.resize(currentSize + rc);
std::memcpy(_buffer.begin() + currentSize, buffer + n, rc);
n += rc;
}
}
return n;
}
else
{
return _pStreamSocketImpl->receiveBytes(buffer, length, MSG_PEEK);
int rc = _pStreamSocketImpl->receiveBytes(buffer, length);
if (rc > 0)
{
_buffer.resize(rc);
std::memcpy(_buffer.begin(), buffer, rc);
_bufferOffset = 0;
}
return rc;
}
}

Expand Down

0 comments on commit 705403d

Please sign in to comment.