diff options
author | Hannes Rantzsch <[email protected]> | 2019-04-26 11:49:42 +0200 |
---|---|---|
committer | Hannes Rantzsch <[email protected]> | 2019-04-26 11:59:45 +0200 |
commit | 9b43c12e39105ccc8fb02a73f27ab807688b979c (patch) | |
tree | 2a5daf0d2d7eda126484eac655d2e3e6e70271eb /src/lib/tls/asio | |
parent | 4670820ea310caf140df23ec6d1319d94666c298 (diff) |
simplify read_some and shutdown
Diffstat (limited to 'src/lib/tls/asio')
-rw-r--r-- | src/lib/tls/asio/asio_stream.h | 59 |
1 files changed, 23 insertions, 36 deletions
diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h index 10fbef784..3459f24e0 100644 --- a/src/lib/tls/asio/asio_stream.h +++ b/src/lib/tls/asio/asio_stream.h @@ -166,7 +166,7 @@ class Stream // const boost::asio::mutable_buffer& input_buffer() { return m_input_buffer; } - boost::asio::const_buffer sendBuffer() const { return m_send_buffer.data(); } // TODO: really .data() ? + boost::asio::const_buffer sendBuffer() const { return m_send_buffer.data(); } //! @brief Check if decrypted data is available in the receive buffer bool hasReceivedData() const { return m_receive_buffer.size() > 0; } @@ -313,20 +313,18 @@ class Stream catch(const TLS_Exception& e) { ec = e.type(); - return; } catch(const Botan::Exception& e) { ec = e.error_type(); - return; } catch(const std::exception&) { ec = Botan::ErrorType::Unknown; - return; } - sendPendingEncryptedData(ec); + if(!ec) + { sendPendingEncryptedData(ec); } } /** @@ -382,11 +380,28 @@ class Stream if(hasReceivedData()) { return copyReceivedData(buffers); } - tls_receive_some(ec); + boost::asio::const_buffer read_buffer{input_buffer().data(), m_nextLayer.read_some(input_buffer(), ec)}; if(ec) { return 0; } - return copyReceivedData(buffers); + try + { + native_handle()->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()); + } + catch(const TLS_Exception& e) + { + ec = e.type(); + } + catch(const Botan::Exception& e) + { + ec = e.error_type(); + } + catch(const std::exception&) + { + ec = Botan::ErrorType::Unknown; + } + + return !ec ? copyReceivedData(buffers) : 0; } /** @@ -598,7 +613,7 @@ class Stream size_t sendPendingEncryptedData(boost::system::error_code& ec) { - if (ec) + if(ec) { return 0; } auto writtenBytes = boost::asio::write(m_nextLayer, sendBuffer(), ec); @@ -606,34 +621,6 @@ class Stream return writtenBytes; } - void tls_receive_some(boost::system::error_code& ec) - { - boost::asio::const_buffer read_buffer{input_buffer().data(), m_nextLayer.read_some(input_buffer(), ec)}; - - if(ec) - { return; } - - try - { - native_handle()->received_data(static_cast<const uint8_t*>(read_buffer.data()), read_buffer.size()); - } - catch(const TLS_Exception& e) - { - ec = e.type(); - return; - } - catch(const Botan::Exception& e) - { - ec = e.error_type(); - return; - } - catch(const std::exception&) - { - ec = Botan::ErrorType::Unknown; - return; - } - } - template <typename ConstBufferSequence> void tls_encrypt(const ConstBufferSequence& buffers, boost::system::error_code& ec) { |