aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorHannes Rantzsch <[email protected]>2019-02-20 11:09:08 +0100
committerHannes Rantzsch <[email protected]>2019-04-16 10:47:49 +0200
commit235471bd84f902db5c44ca4f29388287f0cbb189 (patch)
treee5c3f56961c5f1a511f3766c135857cb8c20aed8 /src/lib
parent9136b994ca305c47950ea465955c044137b0f4a3 (diff)
cleanup async ops
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/tls/asio/asio_async_read_op.h10
-rw-r--r--src/lib/tls/asio/asio_async_write_op.h4
-rw-r--r--src/lib/tls/asio/asio_stream_core.h2
3 files changed, 7 insertions, 9 deletions
diff --git a/src/lib/tls/asio/asio_async_read_op.h b/src/lib/tls/asio/asio_async_read_op.h
index 9535b805a..10add2a7c 100644
--- a/src/lib/tls/asio/asio_async_read_op.h
+++ b/src/lib/tls/asio/asio_async_read_op.h
@@ -34,12 +34,11 @@ struct AsyncReadOperation
~AsyncReadOperation() = default;
AsyncReadOperation(AsyncReadOperation const&) = delete;
- void operator()(boost::system::error_code ec,
- std::size_t bytes_transferred = ~std::size_t(0))
+ void operator()(boost::system::error_code ec, std::size_t bytes_transferred)
{
std::size_t decodedBytes = 0;
- if(bytes_transferred > 0)
+ if(bytes_transferred > 0 && !ec)
{
auto read_buffer =
boost::asio::buffer(m_core.input_buffer, bytes_transferred);
@@ -50,8 +49,7 @@ struct AsyncReadOperation
}
catch(...)
{
- m_handler(convertException(), 0);
- return;
+ ec = convertException();
}
}
@@ -62,7 +60,7 @@ struct AsyncReadOperation
return;
}
- if(m_core.hasReceivedData())
+ if(m_core.hasReceivedData() && !ec)
{
decodedBytes = m_core.copyReceivedData(m_buffers);
ec = boost::system::error_code{};
diff --git a/src/lib/tls/asio/asio_async_write_op.h b/src/lib/tls/asio/asio_async_write_op.h
index d97cce769..1443d18bd 100644
--- a/src/lib/tls/asio/asio_async_write_op.h
+++ b/src/lib/tls/asio/asio_async_write_op.h
@@ -33,11 +33,9 @@ struct AsyncWriteOperation
~AsyncWriteOperation() = default;
AsyncWriteOperation(AsyncWriteOperation const&) = delete;
- void operator()(boost::system::error_code ec,
- std::size_t bytes_transferred = ~std::size_t(0))
+ void operator()(boost::system::error_code ec, std::size_t bytes_transferred)
{
m_core.consumeSendBuffer(bytes_transferred);
- // TODO: make sure returning 0 in error case is correct here--core has already eaten the data
m_handler(ec, ec ? 0 : m_plainBytesTransferred);
}
diff --git a/src/lib/tls/asio/asio_stream_core.h b/src/lib/tls/asio/asio_stream_core.h
index 4ef60a182..ab2c30356 100644
--- a/src/lib/tls/asio/asio_stream_core.h
+++ b/src/lib/tls/asio/asio_stream_core.h
@@ -49,6 +49,8 @@ struct StreamCore : public Botan::TLS::Callbacks
void tls_record_received(uint64_t, const uint8_t data[],
size_t size) override
{
+ // TODO: It would be nice to avoid this buffer copy. However, we need to deal with the case that the receive
+ // buffer provided by the caller is smaller than the decrypted record.
auto buffer = m_receive_buffer.dynamicBuffer.prepare(size);
auto copySize =
boost::asio::buffer_copy(buffer, boost::asio::buffer(data, size));