aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/tls/asio/asio_async_write_op.h9
-rw-r--r--src/lib/tls/asio/asio_stream.h2
-rw-r--r--src/lib/tls/asio/asio_stream_core.h5
-rw-r--r--src/tests/unit_asio_stream.cpp2
4 files changed, 13 insertions, 5 deletions
diff --git a/src/lib/tls/asio/asio_async_write_op.h b/src/lib/tls/asio/asio_async_write_op.h
index ac1d96857..20fa8978e 100644
--- a/src/lib/tls/asio/asio_async_write_op.h
+++ b/src/lib/tls/asio/asio_async_write_op.h
@@ -51,10 +51,11 @@ struct AsyncWriteOperation : public AsyncBase<Handler, typename Stream::executor
{
m_core.consumeSendBuffer(bytes_transferred);
- if(m_core.hasDataToSend() && !ec){
- boost::asio::async_write(m_stream.next_layer(), m_core.sendBuffer(), std::move(*this));
+ if(m_core.hasDataToSend() && !ec)
+ {
+ m_stream.next_layer().async_write_some(m_core.sendBuffer(), std::move(*this));
return;
- }
+ }
if(!isContinuation)
{
@@ -65,7 +66,7 @@ struct AsyncWriteOperation : public AsyncBase<Handler, typename Stream::executor
// the size of the sent TLS record can differ from the size of the payload due to TLS encryption. We need to tell
// the handler how many bytes of the original data we already processed.
- this->complete_now(ec, ec ? 0 : m_plainBytesTransferred);
+ this->complete_now(ec, m_plainBytesTransferred);
}
}
diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h
index e52684bfa..49b7510dd 100644
--- a/src/lib/tls/asio/asio_stream.h
+++ b/src/lib/tls/asio/asio_stream.h
@@ -379,6 +379,8 @@ class Stream : public StreamBase<Channel>
}
catch(const std::exception&)
{
+ // we can't be sure how many bytes were commited here, so clear the send_buffer and try again
+ this->m_core.clearSendBuffer();
Botan::TLS::AsyncWriteOperation<typename std::decay<WriteHandler>::type, Stream>
op{std::move(init.completion_handler),
*this,
diff --git a/src/lib/tls/asio/asio_stream_core.h b/src/lib/tls/asio/asio_stream_core.h
index 3bf65fe46..74b0998f1 100644
--- a/src/lib/tls/asio/asio_stream_core.h
+++ b/src/lib/tls/asio/asio_stream_core.h
@@ -106,6 +106,11 @@ struct StreamCore : public Botan::TLS::Callbacks
m_send_buffer.dynamicBuffer.consume(bytesConsumed);
}
+ void clearSendBuffer()
+ {
+ consumeSendBuffer(m_send_buffer.dynamicBuffer.size());
+ }
+
private:
// Buffer space used to read input intended for the engine.
std::vector<uint8_t> m_input_buffer_space;
diff --git a/src/tests/unit_asio_stream.cpp b/src/tests/unit_asio_stream.cpp
index 9800dfc32..dcb0783de 100644
--- a/src/tests/unit_asio_stream.cpp
+++ b/src/tests/unit_asio_stream.cpp
@@ -671,7 +671,7 @@ class Asio_Stream_Tests final : public Test
auto write_handler = [&](const error_code &ec, std::size_t bytes_transferred)
{
- result.test_eq("didn't transfer anything", bytes_transferred, 0);
+ result.test_eq("committed some bytes to the core", bytes_transferred, TEST_DATA_SIZE);
result.confirm("propagates error code", ec == net::error::eof);
};