diff --git a/Subtrees/beast/modules/beast_asio/sockets/beast_Socket.cpp b/Subtrees/beast/modules/beast_asio/sockets/beast_Socket.cpp index ef07e40dc2..e67bc1a27b 100644 --- a/Subtrees/beast/modules/beast_asio/sockets/beast_Socket.cpp +++ b/Subtrees/beast/modules/beast_asio/sockets/beast_Socket.cpp @@ -247,3 +247,71 @@ Socket::async_shutdown (BOOST_ASIO_MOVE_ARG(ErrorCall) handler) #endif } +//------------------------------------------------------------------------------ + + +#if 0 +/* Stream, SyncReadStream, AsyncReadStream, WriteStream, AsyncWriteStream */ +// Note, missing std::future<> returns +class Stream +{ +public: + // Stream + typedef typename remove_reference::type next_layer_type; + typedef typename next_layer_type::lowest_layer_type lowest_layer_type; + next_layer_type& next_layer() + next_layer_type const& next_layer() const + lowest_layer_type& lowest_layer() + const lowest_layer_type& lowest_layer() const + boost::asio::io_service& get_io_service() + void close() + boost::system::error_code close(boost::system::error_code& ec) + + // SyncWriteStream + template + std::size_t write_some (const ConstBufferSequence& buffers) + template + std::size_t write_some (const ConstBufferSequence& buffers, boost::system::error_code& ec) + + // AsyncWriteStream + template + void async_write_some (const ConstBufferSequence& buffers, WriteHandler handler) + + // ReadStream + template + std::size_t read_some (const MutableBufferSequence& buffers) + template + std::size_t read_some (const MutableBufferSequence& buffers, boost::system::error_code& ec) + + // AsyncReadStream + template + void async_read_some (const MutableBufferSequence& buffers, ReadHandler handler) +}; +#endif +/* members, and the most common base class in which they appear: + +basic_io_object + io_service& get_io_service () + +basic_socket : basic_io_object + typedef protocol_type + typedef lowest_layer_type + lowest_layer_type& lowest_layer () + native_handle () // Socket::native_handle() would return void* and we'd use the templates to do the static_cast + cancel () + shutdon (shutdown_type) + close () + + +basic_socket_acceptor : basic_io_object + typedef protocol_type + native_handle () + listen () + accept () + async_accept () + cancel () + close () + +basic_stream_socket : basic_socket + +*/ diff --git a/Subtrees/beast/modules/beast_asio/sockets/beast_SocketWrapper.h b/Subtrees/beast/modules/beast_asio/sockets/beast_SocketWrapper.h index c83bea6590..9e0fdd5d65 100644 --- a/Subtrees/beast/modules/beast_asio/sockets/beast_SocketWrapper.h +++ b/Subtrees/beast/modules/beast_asio/sockets/beast_SocketWrapper.h @@ -644,4 +644,15 @@ public: Object* m_impl; }; +//------------------------------------------------------------------------------ + +/** Dynamically allocate a SocketWrapper. + This deduces the template arguments for convenience. +*/ +template +SocketWrapper * newSocketWrapper (Object& object) +{ + return new SocketWrapper (object); +} + #endif diff --git a/Subtrees/beast/modules/beast_asio/sockets/beast_SocketWrapperBasics.h b/Subtrees/beast/modules/beast_asio/sockets/beast_SocketWrapperBasics.h index 069e01b15d..6c7e2f948a 100644 --- a/Subtrees/beast/modules/beast_asio/sockets/beast_SocketWrapperBasics.h +++ b/Subtrees/beast/modules/beast_asio/sockets/beast_SocketWrapperBasics.h @@ -76,6 +76,30 @@ protected: typedef value type; }; + // Specialization for boost::asio::buffered_stream + template + struct InterfacesOf > + { + struct value : SocketInterface::Stream { }; + typedef value type; + }; + + // Specialization for boost::asio::buffered_read_stream + template + struct InterfacesOf > + { + struct value : SocketInterface::Stream { }; + typedef value type; + }; + + // Specialization for boost::asio::buffered_write_stream + template + struct InterfacesOf > + { + struct value : SocketInterface::Stream { }; + typedef value type; + }; + // Specialization for boost::asio::ssl::stream template struct InterfacesOf > diff --git a/Subtrees/beast/modules/beast_asio/tests/beast_PeerTest.cpp b/Subtrees/beast/modules/beast_asio/tests/beast_PeerTest.cpp index 4b9c26f6ce..38b0ac717e 100644 --- a/Subtrees/beast/modules/beast_asio/tests/beast_PeerTest.cpp +++ b/Subtrees/beast/modules/beast_asio/tests/beast_PeerTest.cpp @@ -26,7 +26,7 @@ PeerTest::Result::Result () PeerTest::Result::Result (boost::system::error_code const& ec, String const& prefix) : m_ec (ec) , m_message ((prefix == String::empty) ? ec.message () - : prefix + " " + ec.message ()) + : prefix + ": " + ec.message ()) { } diff --git a/Subtrees/beast/modules/beast_asio/tests/beast_PeerTest.h b/Subtrees/beast/modules/beast_asio/tests/beast_PeerTest.h index 4c33a7f0d1..0a8f3a1a22 100644 --- a/Subtrees/beast/modules/beast_asio/tests/beast_PeerTest.h +++ b/Subtrees/beast/modules/beast_asio/tests/beast_PeerTest.h @@ -105,27 +105,25 @@ public: /** Test two peers and return the results. */ - template - static Results run (Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds) + template + static Results run (ClientArg const& clientArg, ServerArg const& serverArg, int timeoutSeconds = defaultTimeoutSeconds) { Results results; if (Process::isRunningUnderDebugger ()) timeoutSeconds = -1; - results.name = Details::getArgName (arg); - try { - TestPeerType server (arg); + TestPeerType server (serverArg); - results.name << " / " << server.name (); + results.name = server.name () + Details::getArgName (serverArg); try { - TestPeerType client (arg); + TestPeerType client (clientArg); - results.name << " / " << client.name (); + results.name << " / " + client.name () + Details::getArgName (clientArg); try { @@ -179,6 +177,12 @@ public: return results; } + template + static Results run (Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds) + { + return run (arg, arg, timeoutSeconds); + } + //-------------------------------------------------------------------------- /** Reports tests of Details for all known asynchronous logic combinations to a UnitTest. @@ -188,7 +192,7 @@ public: int timeoutSeconds = defaultTimeoutSeconds, bool beginTestCase = true) { - run + run (arg, timeoutSeconds).report (test, beginTestCase); } @@ -199,13 +203,13 @@ public: int timeoutSeconds = defaultTimeoutSeconds, bool beginTestCase = true) { - run + run (arg, timeoutSeconds).report (test, beginTestCase); - run + run (arg, timeoutSeconds).report (test, beginTestCase); - run + run (arg, timeoutSeconds).report (test, beginTestCase); report_async
(test, arg, timeoutSeconds, beginTestCase); diff --git a/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerDetailsTcp.h b/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerDetailsTcp.h index 72ac36fa79..a93e8537ed 100644 --- a/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerDetailsTcp.h +++ b/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerDetailsTcp.h @@ -48,10 +48,10 @@ public: static String getArgName (arg_type arg) { if (arg == protocol_type::v4 ()) - return "tcpv4"; + return ".tcpv4"; else if (arg == protocol_type::v6 ()) - return "tcpv6"; - return "tcp?"; + return ".tcpv6"; + return ".tcp?"; } String name () diff --git a/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp b/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp index c431beae38..c098f6d2b4 100644 --- a/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp +++ b/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerLogicAsyncClient.cpp @@ -135,10 +135,18 @@ void TestPeerLogicAsyncClient::on_shutdown (error_code const& ec) { if (success (error (ec), true)) { - if (success (socket ().close (error ()))) + if (socket ().requires_handshake ()) { - // doing nothing here is intended, - // as the calls to success() may set error() + socket ().shutdown (Socket::shutdown_both, error ()); + } + + if (! error ()) + { + if (success (socket ().close (error ()))) + { + // doing nothing here is intended, + // as the calls to success() may set error() + } } } } diff --git a/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp b/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp index 46fa6cfb1e..a926dfdae6 100644 --- a/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp +++ b/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerLogicAsyncServer.cpp @@ -100,6 +100,11 @@ void TestPeerLogicAsyncServer::on_shutdown (error_code const& ec) { if (success (error (ec), true)) { + if (socket ().requires_handshake ()) + { + socket ().shutdown (Socket::shutdown_both, error ()); + } + if (success (socket ().close (error ()))) { // doing nothing here is intended, diff --git a/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerUnitTests.cpp b/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerUnitTests.cpp index 8c5c1b3ba0..c79b1ceffd 100644 --- a/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerUnitTests.cpp +++ b/Subtrees/beast/modules/beast_asio/tests/beast_TestPeerUnitTests.cpp @@ -22,14 +22,6 @@ class TestPeerUnitTests : public UnitTest { public: - enum - { - timeoutSeconds = 3 - }; - - TestPeerUnitTests () : UnitTest ("TestPeer", "beast", runManual) - { - } template void testDetails (Arg const& arg = Arg ()) @@ -43,6 +35,17 @@ public: testDetails (protocol::v4 ()); testDetails (protocol::v6 ()); } + + //-------------------------------------------------------------------------- + + enum + { + timeoutSeconds = 10 + }; + + TestPeerUnitTests () : UnitTest ("TestPeer", "beast", runManual) + { + } }; static TestPeerUnitTests testPeerUnitTests;