Skip to content

Commit

Permalink
Fix getSendBuffer reordering bug
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Sep 30, 2021
1 parent 6ec6f00 commit 7956546
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/AsyncSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,22 @@ struct AsyncSocket {
return {sendBuffer, SendBufferAttribute::NEEDS_UNCORK};
}
} else {

/* If we are corked and there is already data in the cork buffer,
mark how much is ours and reset it */
unsigned int ourCorkOffset = 0;
if (isCorked() && loopData->corkOffset) {
ourCorkOffset = loopData->corkOffset;
loopData->corkOffset = 0;
}

/* Fallback is to use the backpressure as buffer */
backPressure.resize(existingBackpressure + size);
return {(char *) backPressure.data() + existingBackpressure, SendBufferAttribute::NEEDS_DRAIN};
backPressure.resize(ourCorkOffset + existingBackpressure + size);

/* And copy corkbuffer in front */
memcpy((char *) backPressure.data() + existingBackpressure, loopData->corkBuffer, ourCorkOffset);

return {(char *) backPressure.data() + ourCorkOffset + existingBackpressure, SendBufferAttribute::NEEDS_DRAIN};
}
}

Expand Down

0 comments on commit 7956546

Please sign in to comment.