From d959af430e15df2e64e2337abab32fea269e28e3 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Fri, 16 Aug 2013 16:10:55 -0700 Subject: [PATCH] Fixes to handshake and socket wrapper --- .../handshake/beast_HandshakeDetectStream.h | 22 ++++++++++++++----- modules/beast_asio/sockets/beast_Socket.cpp | 2 +- modules/beast_asio/sockets/beast_Socket.h | 4 ++-- .../beast_asio/sockets/beast_SocketWrapper.h | 2 +- .../tests/beast_TestPeerLogicAsyncClient.cpp | 6 ++--- .../tests/beast_TestPeerLogicAsyncServer.cpp | 6 ++--- .../tests/beast_TestPeerLogicSyncClient.cpp | 4 ++-- .../tests/beast_TestPeerLogicSyncServer.cpp | 4 ++-- 8 files changed, 30 insertions(+), 20 deletions(-) diff --git a/modules/beast_asio/handshake/beast_HandshakeDetectStream.h b/modules/beast_asio/handshake/beast_HandshakeDetectStream.h index d5c710709..72df997a3 100644 --- a/modules/beast_asio/handshake/beast_HandshakeDetectStream.h +++ b/modules/beast_asio/handshake/beast_HandshakeDetectStream.h @@ -146,15 +146,18 @@ public: { #if BEAST_ASIO_HAS_FUTURE_RETURNS boost::asio::detail::async_result_init< - ErrorCall, void (error_code)> init( + HandshakeHandler, void (error_code)> init( BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler)); // init.handler is copied - m_origHandler = ErrorCall (HandshakeHandler(init.handler)); + m_origHandler = ErrorCall ( + BOOST_ASIO_MOVE_CAST(HandshakeHandler) + (HandshakeHandler(init.handler))); bassert (m_origBufferedHandler.isNull ()); async_do_handshake (type, ConstBuffers ()); return init.result.get(); #else - m_origHandler = ErrorCall (handler); + m_origHandler = ErrorCall ( + BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler)); bassert (m_origBufferedHandler.isNull ()); async_do_handshake (type, ConstBuffers ()); #endif @@ -165,7 +168,7 @@ public: error_code handshake (handshake_type type, const ConstBufferSequence& buffers, error_code& ec) { - return do_handshake (type, ec, ConstBuffers (buffers));; + return do_handshake (type, ec, ConstBuffers (buffers)); } template @@ -178,12 +181,15 @@ public: BufferedHandshakeHandler, void (error_code, std::size_t)> init( BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler)); // init.handler is copied - m_origBufferedHandler = TransferCall (BufferedHandshakeHandler(init.handler)); + m_origBufferedHandler = TransferCall ( + BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler) + (BufferedHandshakeHandler(init.handler))); bassert (m_origHandler.isNull ()); async_do_handshake (type, ConstBuffers (buffers)); return init.result.get(); #else - m_origBufferedHandler = TransferCall (handler); + m_origBufferedHandler = TransferCall ( + BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler(handler))); bassert (m_origHandler.isNull ()); async_do_handshake (type, ConstBuffers (buffers)); #endif @@ -240,6 +246,8 @@ public: void async_do_handshake (handshake_type type, ConstBuffers const& buffers) { // Transfer caller data to our buffer. + // We commit the bytes in on_async_read_some. + // std::size_t const bytes_transferred (boost::asio::buffer_copy ( m_buffer.prepare (boost::asio::buffer_size (buffers)), buffers)); @@ -275,6 +283,7 @@ public: // continuation? m_callback->on_async_detect (m_logic.get (), ec, ConstBuffers (m_buffer.data ()), m_origBufferedHandler); + return; } #endif @@ -283,6 +292,7 @@ public: // continuation? m_callback->on_async_detect (m_logic.get (), ec, ConstBuffers (m_buffer.data ()), m_origHandler); + return; } diff --git a/modules/beast_asio/sockets/beast_Socket.cpp b/modules/beast_asio/sockets/beast_Socket.cpp index 2dfc4116f..55237ab30 100644 --- a/modules/beast_asio/sockets/beast_Socket.cpp +++ b/modules/beast_asio/sockets/beast_Socket.cpp @@ -154,7 +154,7 @@ Socket::async_write_some (ConstBuffers const&, BOOST_ASIO_MOVE_ARG(TransferCall) // ssl::stream // -bool Socket::requires_handshake () +bool Socket::needs_handshake () { return false; } diff --git a/modules/beast_asio/sockets/beast_Socket.h b/modules/beast_asio/sockets/beast_Socket.h index a9bf4c285..d9da72bcd 100644 --- a/modules/beast_asio/sockets/beast_Socket.h +++ b/modules/beast_asio/sockets/beast_Socket.h @@ -240,7 +240,7 @@ public: /** Determines if the underlying stream requires a handshake. - If requires_handshake is true, it will be necessary to call handshake or + If needs_handshake is true, it will be necessary to call handshake or async_handshake after the connection is established. Furthermore it will be necessary to call the shutdown member from the HandshakeInterface to close the connection. Do not close the underlying @@ -250,7 +250,7 @@ public: The default version returns false. */ - virtual bool requires_handshake (); + virtual bool needs_handshake (); // ssl::stream::handshake (1 of 4) // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ssl__stream/handshake/overload1.html diff --git a/modules/beast_asio/sockets/beast_SocketWrapper.h b/modules/beast_asio/sockets/beast_SocketWrapper.h index d13f3923e..77cc8e229 100644 --- a/modules/beast_asio/sockets/beast_SocketWrapper.h +++ b/modules/beast_asio/sockets/beast_SocketWrapper.h @@ -549,7 +549,7 @@ public: // ssl::stream // - bool requires_handshake () + bool needs_handshake () { using namespace SocketWrapperMemberChecks; return diff --git a/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp b/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp index c098f6d2b..0b6f58523 100644 --- a/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp +++ b/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp @@ -37,7 +37,7 @@ void TestPeerLogicAsyncClient::on_connect_async (error_code const& ec) if (aborted (ec) || failure (error (ec))) return finished (); - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { socket ().async_handshake (Socket::client, boost::bind (&TestPeerLogicAsyncClient::on_handshake, this, @@ -99,7 +99,7 @@ void TestPeerLogicAsyncClient::on_read_final (error_code const& ec, std::size_t) // if (ec == boost::asio::error::eof) { - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { socket ().async_shutdown (boost::bind (&TestPeerLogicAsyncClient::on_shutdown, this, boost::asio::placeholders::error)); @@ -135,7 +135,7 @@ void TestPeerLogicAsyncClient::on_shutdown (error_code const& ec) { if (success (error (ec), true)) { - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { socket ().shutdown (Socket::shutdown_both, error ()); } diff --git a/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp b/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp index a926dfdae..c290b5413 100644 --- a/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp +++ b/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp @@ -37,7 +37,7 @@ void TestPeerLogicAsyncServer::on_connect_async (error_code const& ec) if (aborted (ec) || failure (error (ec))) return finished (); - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { socket ().async_handshake (Socket::server, boost::bind (&TestPeerLogicAsyncServer::on_handshake, this, @@ -80,7 +80,7 @@ void TestPeerLogicAsyncServer::on_write (error_code const& ec, std::size_t bytes if (unexpected (bytes_transferred == 7, error ())) return finished (); - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { socket ().async_shutdown (boost::bind (&TestPeerLogicAsyncServer::on_shutdown, this, boost::asio::placeholders::error)); @@ -100,7 +100,7 @@ void TestPeerLogicAsyncServer::on_shutdown (error_code const& ec) { if (success (error (ec), true)) { - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { socket ().shutdown (Socket::shutdown_both, error ()); } diff --git a/modules/beast_asio/tests/beast_TestPeerLogicSyncClient.cpp b/modules/beast_asio/tests/beast_TestPeerLogicSyncClient.cpp index 9b579090b..4fa98893a 100644 --- a/modules/beast_asio/tests/beast_TestPeerLogicSyncClient.cpp +++ b/modules/beast_asio/tests/beast_TestPeerLogicSyncClient.cpp @@ -41,7 +41,7 @@ void TestPeerLogicSyncClient::on_connect () return ; } - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { if (failure (socket ().handshake (to_handshake_type (get_role ()), error ()))) return; @@ -90,7 +90,7 @@ void TestPeerLogicSyncClient::on_connect () } } - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { if (failure (socket ().shutdown (error ()), true)) return; diff --git a/modules/beast_asio/tests/beast_TestPeerLogicSyncServer.cpp b/modules/beast_asio/tests/beast_TestPeerLogicSyncServer.cpp index b19a1f9e8..a1358c83f 100644 --- a/modules/beast_asio/tests/beast_TestPeerLogicSyncServer.cpp +++ b/modules/beast_asio/tests/beast_TestPeerLogicSyncServer.cpp @@ -34,7 +34,7 @@ TestPeerBasics::Model TestPeerLogicSyncServer::get_model () const noexcept void TestPeerLogicSyncServer::on_connect () { - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { if (failure (socket ().handshake (to_handshake_type (get_role ()), error ()))) return; @@ -66,7 +66,7 @@ void TestPeerLogicSyncServer::on_connect () return; } - if (socket ().requires_handshake ()) + if (socket ().needs_handshake ()) { if (failure (socket ().shutdown (error ()), true)) return;