aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/tls/asio
diff options
context:
space:
mode:
authorTim Oesterreich <[email protected]>2019-03-06 17:09:37 +0100
committerHannes Rantzsch <[email protected]>2019-04-16 10:48:14 +0200
commitfb373394350cbe4f04d6958ffa8f33882f690b1e (patch)
treee40b6cc5c3f477f45ba9a95ec0636b930e3f7cd5 /src/lib/tls/asio
parentb1acdbfe4f6ed49691dc16e74bd8906bedf3c625 (diff)
async_write_some returns amount of bytes commited to the core, instead of bytes sent on the wire; do not use boost::asio::async_read/write
Diffstat (limited to 'src/lib/tls/asio')
-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
3 files changed, 12 insertions, 4 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;