Skip to content

Commit

Permalink
Ensure partially read frame buffer is always large enough to hold frame
Browse files Browse the repository at this point in the history
amqpprox internally buffers partial frames until the full frame is in memory,
at which point they are sent to the broker or client (depending on direction).

If there is no data internally buffered when data becomes available on the socket,
amqpprox creates a buffer of exactly the required size. Sometimes - e.g. When amqpprox
is quite busy - the requested buffer is larger than expected. This causes the
partial-frame buffer swap operation to fail.
  • Loading branch information
adamncasey committed May 9, 2023
1 parent 594544e commit 8ae42b4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions libamqpprox/amqpprox_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,10 @@ inline void Session::copyRemaining(FlowType direction, const Buffer &remaining)
if (remaining.size()) {
d_serverWaterMark = remaining.size();
d_serverWriteDataHandle.swap(d_serverDataHandle);
d_bufferPool_p->acquireBuffer(&d_serverDataHandle,
Frame::getMaxFrameSize());
d_bufferPool_p->acquireBuffer(
&d_serverDataHandle,
std::max(d_serverWaterMark, Frame::getMaxFrameSize()));

memcpy(
d_serverDataHandle.data(), remaining.ptr(), d_serverWaterMark);
}
Expand All @@ -355,8 +357,9 @@ inline void Session::copyRemaining(FlowType direction, const Buffer &remaining)
if (remaining.size()) {
d_clientWaterMark = remaining.size();
d_clientWriteDataHandle.swap(d_clientDataHandle);
d_bufferPool_p->acquireBuffer(&d_clientDataHandle,
Frame::getMaxFrameSize());
d_bufferPool_p->acquireBuffer(
&d_clientDataHandle,
std::max(d_clientWaterMark, Frame::getMaxFrameSize()));
memcpy(
d_clientDataHandle.data(), remaining.ptr(), d_clientWaterMark);
}
Expand Down

0 comments on commit 8ae42b4

Please sign in to comment.