Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adamncasey committed Apr 11, 2022
1 parent 6856be2 commit f79263b
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions libamqpprox/amqpprox_maybesecuresocketadaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class MaybeSecureSocketAdaptor {
, d_socket()
, d_secured(secured)
, d_handshook(false)
, d_smallBuffer(0)
, d_smallBufferSet(false)
{
}
#endif
Expand All @@ -85,10 +87,10 @@ class MaybeSecureSocketAdaptor {
, d_smallBuffer(src.d_smallBuffer)
, d_smallBufferSet(src.d_smallBufferSet)
{
src.d_socket = std::unique_ptr<stream_type>();
src.d_secured = false;
src.d_handshook = false;
src.d_smallBuffer = 0;
src.d_socket = std::unique_ptr<stream_type>();
src.d_secured = false;
src.d_handshook = false;
src.d_smallBuffer = 0;
src.d_smallBufferSet = false;
}

Expand Down Expand Up @@ -323,15 +325,22 @@ class MaybeSecureSocketAdaptor {

if (isSecure()) {
if (d_smallBufferSet) {
// The reader missed a byte - invoke ssl async_read_some(zero-sized-buffer) so the
// handler is immediately invoked to collect this missing byte.
// This codepath wasn't hit during testing, but it's left here for completeness
return d_socket->async_read_some(boost::asio::buffer(&d_smallBuffer, 0), handler);
// The reader missed a byte - invoke ssl
// async_read_some(zero-sized-buffer) so the handler is
// immediately invoked to collect this missing byte. This
// codepath wasn't hit during testing, but it's left here for
// completeness
LOG_DEBUG << "Invoked async_read_some again before reading "
"data. Immediately invoking handler";

return d_socket->async_read_some(
boost::asio::buffer(nullptr, 0), handler);
}

// async_read_some with a one byte buffer to ensure we are only called with useful progress
// async_read_some with a one byte buffer to ensure we are only
// called with useful progress
return d_socket->async_read_some(
boost::asio::buffer(&d_smallBuffer, 1),
boost::asio::buffer(&d_smallBuffer, sizeof(d_smallBuffer)),
[this, handler](boost::system::error_code ec,
std::size_t length) {
if (length != 0) {
Expand Down

0 comments on commit f79263b

Please sign in to comment.