Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/perf/lib/Tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,9 @@ bool TcpConnection::ProcessReceiveData(const uint8_t* Buffer, uint32_t BufferLen
{
if (BufferedDataLength) {
if (BufferedDataLength < sizeof(TcpFrame)) {
//
// A partial header was buffered, keep buffering until we have a full header.
//
if (BufferedDataLength + BufferLength < sizeof(TcpFrame)) {
goto BufferData;
}
Expand All @@ -857,8 +860,15 @@ bool TcpConnection::ProcessReceiveData(const uint8_t* Buffer, uint32_t BufferLen
BufferLength -= ExtraLength;
}

//
// A partial frame is buffered, keep buffering until we have a full frame.
//
auto Frame = (TcpFrame*)BufferedData;
Comment thread
gaurav2699 marked this conversation as resolved.
auto FrameLength = (uint32_t)sizeof(TcpFrame) + Frame->Length + CXPLAT_ENCRYPTION_OVERHEAD;
auto FrameLength = sizeof(TcpFrame) + Frame->Length + CXPLAT_ENCRYPTION_OVERHEAD;
if (FrameLength > sizeof(BufferedData)) {
WriteOutput("ProcessReceiveData FAILED invalid frame length\n");
return false;
}
auto BytesNeeded = FrameLength - BufferedDataLength;
if (BufferLength < BytesNeeded) {
goto BufferData;
Expand All @@ -870,12 +880,18 @@ bool TcpConnection::ProcessReceiveData(const uint8_t* Buffer, uint32_t BufferLen
Buffer += BytesNeeded;
BufferLength -= BytesNeeded;

//
// Process the buffered frame now that it is complete.
//
if (!ProcessReceiveFrame(Frame)) {
return false;
}
BufferedDataLength = 0;
}

//
// Process as many full frames as possible.
//
while (BufferLength) {
auto Frame = (TcpFrame*)Buffer;
if (BufferLength < sizeof(TcpFrame) ||
Expand All @@ -895,6 +911,13 @@ bool TcpConnection::ProcessReceiveData(const uint8_t* Buffer, uint32_t BufferLen

BufferData:

//
// Buffer any remaining bytes.
//
if (BufferedDataLength + BufferLength > sizeof(BufferedData)) {
Comment thread
gaurav2699 marked this conversation as resolved.
WriteOutput("ProcessReceiveData FAILED invalid frame length\n");
return false;
}
CxPlatCopyMemory(BufferedData+BufferedDataLength, Buffer, BufferLength);
BufferedDataLength += BufferLength;

Expand Down
Loading