diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj index 863017b823..cdc39ec662 100644 --- a/Builds/VisualStudio2012/beast.vcxproj +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -76,6 +76,7 @@ + diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters index 97c40163d7..a2c09e4306 100644 --- a/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Builds/VisualStudio2012/beast.vcxproj.filters @@ -146,6 +146,9 @@ {af535ad5-a06c-462f-8ac0-8207a708e032} + + {c7a576bb-27b2-486e-aa14-3c51aa86c50f} + @@ -764,6 +767,9 @@ beast_asio\sockets + + beast_asio\system + diff --git a/modules/beast_asio/beast_asio.h b/modules/beast_asio/beast_asio.h index 8429bac781..930cb4268a 100644 --- a/modules/beast_asio/beast_asio.h +++ b/modules/beast_asio/beast_asio.h @@ -40,42 +40,8 @@ // Must come before boost includes to fix the bost placeholders. #include "../beast_core/beast_core.h" -//------------------------------------------------------------------------------ - /* This module requires boost and possibly OpenSSL */ - -// Make sure we take care of fixing boost::bind oddities first. -#if !defined(BEAST_CORE_H_INCLUDED) -#error beast_core.h must be included before including this file -#endif - -#if BEAST_WIN32 -# ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x0600 -# endif -# ifndef _VARIADIC_MAX -# define _VARIADIC_MAX 10 -# endif -#endif - -#include -#include -#include -#include - -//#include -//#include -//#include -//#include -//#include -//#include - -// VFALCO TODO check for version availability -#ifndef BOOST_ASIO_INITFN_RESULT_TYPE -#define BOOST_ASIO_INITFN_RESULT_TYPE(expr,val) void -#endif - -//------------------------------------------------------------------------------ +#include "system/beast_BoostIncludes.h" namespace beast { diff --git a/modules/beast_asio/sockets/beast_Socket.h b/modules/beast_asio/sockets/beast_Socket.h index bfa4804d0b..43925bf527 100644 --- a/modules/beast_asio/sockets/beast_Socket.h +++ b/modules/beast_asio/sockets/beast_Socket.h @@ -54,6 +54,19 @@ public: // //-------------------------------------------------------------------------- +#if 0 + typedef Socket next_layer_type; + typedef Socket lowest_layer_type; + + virtual next_layer_type& next_layer () = 0; + + virtual next_layer_type const& next_layer () const = 0; + + virtual lowest_layer_type& lowest_layer () = 0; + + virtual lowest_layer_type const& lowest_layer () const = 0; +#endif + /** Determines if the underlying stream requires a handshake. If is_handshaked is true, it will be necessary to call handshake or @@ -85,20 +98,21 @@ public: @endcode */ + template - Object* native_object () + Object& native_object () { void* const object = native_object_raw (); - if (object != nullptr) - return dynamic_cast (object); - return object; + if (object == nullptr) + throw std::bad_cast ("null pointer"); + return *static_cast (object); } virtual void* native_object_raw () = 0; //-------------------------------------------------------------------------- // - // SocketInterface + // SocketInterface::Socket // //-------------------------------------------------------------------------- @@ -116,7 +130,8 @@ public: throw_error (shutdown (what, ec)); } - virtual boost::system::error_code shutdown (shutdown_type what, boost::system::error_code& ec) = 0; + virtual boost::system::error_code shutdown (shutdown_type what, + boost::system::error_code& ec) = 0; void close () { @@ -128,7 +143,7 @@ public: //-------------------------------------------------------------------------- // - // StreamInterface + // SocketInterface::Stream // //-------------------------------------------------------------------------- @@ -137,12 +152,14 @@ public: // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/SyncReadStream.html // template - std::size_t read_some (MutableBufferSequence const& buffers, boost::system::error_code& ec) + std::size_t read_some (MutableBufferSequence const& buffers, + boost::system::error_code& ec) { - return read_some_impl (MutableBuffers (buffers), ec); + return read_some (MutableBuffers (buffers), ec); } - virtual std::size_t read_some_impl (MutableBuffers const& buffers, boost::system::error_code& ec) = 0; + virtual std::size_t read_some (BOOST_ASIO_MOVE_ARG(MutableBuffers) buffers, + boost::system::error_code& ec) = 0; // SyncWriteStream // @@ -151,40 +168,44 @@ public: template std::size_t write_some (ConstBufferSequence const& buffers, boost::system::error_code &ec) { - return write_some_impl (ConstBuffers (buffers), ec); + return write_some (ConstBuffers (buffers), ec); } - virtual std::size_t write_some_impl (ConstBuffers const& buffers, boost::system::error_code& ec) = 0; + virtual std::size_t write_some (BOOST_ASIO_MOVE_ARG(ConstBuffers) buffers, boost::system::error_code& ec) = 0; // AsyncReadStream // // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/AsyncReadStream.html // template - void async_read_some (MutableBufferSequence const& buffers, - BOOST_ASIO_MOVE_ARG(ReadHandler) handler) + BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void (boost::system::error_code, std::size_t)) + async_read_some (MutableBufferSequence const& buffers, BOOST_ASIO_MOVE_ARG(ReadHandler) handler) { - async_read_some_impl (MutableBuffers (buffers), handler); + return async_read_some (MutableBuffers (buffers), TransferCall(handler)); } - virtual void async_read_some_impl (MutableBuffers const& buffers, TransferCall const& call) = 0; + virtual + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t)) + async_read_some (BOOST_ASIO_MOVE_ARG(MutableBuffers) buffers, BOOST_ASIO_MOVE_ARG(TransferCall) call) = 0; // AsyncWriteStream // // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/AsyncWriteStream.html // template - void async_write_some (ConstBufferSequence const& buffers, - BOOST_ASIO_MOVE_ARG(WriteHandler) handler) + BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void (boost::system::error_code, std::size_t)) + async_write_some (ConstBufferSequence const& buffers, BOOST_ASIO_MOVE_ARG(WriteHandler) handler) { - async_write_some_impl (ConstBuffers (buffers), handler); + return async_write_some (ConstBuffers (buffers), TransferCall(handler)); } - virtual void async_write_some_impl (ConstBuffers const& buffers, TransferCall const& call) = 0; + virtual + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t)) + async_write_some (BOOST_ASIO_MOVE_ARG(ConstBuffers) buffers, BOOST_ASIO_MOVE_ARG(TransferCall) call) = 0; //-------------------------------------------------------------------------- // - // HandshakeInterface + // SocketInterface::Handshake // //-------------------------------------------------------------------------- @@ -200,9 +221,24 @@ public: // ssl::stream::handshake (2 of 4) // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ssl__stream/handshake/overload2.html // - virtual boost::system::error_code handshake (handshake_type role, boost::system::error_code& ec) = 0; + virtual boost::system::error_code handshake (handshake_type role, + boost::system::error_code& ec) = 0; -#if (BOOST_VERSION / 100) >= 1054 + // ssl::stream::async_handshake (1 of 2) + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ssl__stream/async_handshake/overload1.html + // + template + BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, void (boost::system::error_code)) + async_handshake (handshake_type role, BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler) + { + return async_handshake (role, ErrorCall (handler)); + } + + virtual + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(ErrorCall, void (boost::system::error_code)) + async_handshake (handshake_type role, BOOST_ASIO_MOVE_ARG(ErrorCall) call) = 0; + +#if BOOST_ASIO_HAS_BUFFEREDHANDSHAKE // ssl::stream::handshake (3 of 4) // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ssl__stream/handshake/overload3.html // @@ -220,37 +256,26 @@ public: boost::system::error_code handshake (handshake_type role, ConstBufferSequence const& buffers, boost::system::error_code& ec) { - return handshake_impl (role, ConstBuffers (buffers), ec); + return handshake (role, ConstBuffers (buffers), ec); } - virtual boost::system::error_code handshake_impl (handshake_type role, - ConstBuffers const& buffers, boost::system::error_code& ec) = 0; -#endif + virtual boost::system::error_code handshake (handshake_type role, + BOOST_ASIO_MOVE_ARG(ConstBuffers) buffers, boost::system::error_code& ec) = 0; - // ssl::stream::async_handshake (1 of 2) - // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ssl__stream/async_handshake/overload1.html - // - template - void async_handshake (handshake_type role, BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler) - { - async_handshake_impl (role, handler); - } - - virtual void async_handshake_impl (handshake_type role, ErrorCall const& calll) = 0; - -#if (BOOST_VERSION / 100) >= 1054 // ssl::stream::async_handshake (2 of 2) // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ssl__stream/async_handshake/overload2.html // template - void async_handshake (handshake_type role, ConstBufferSequence const& buffers, + BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler, void (boost::system::error_code, std::size_t)) + async_handshake (handshake_type role, ConstBufferSequence const& buffers, BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler) { - async_handshake_impl (role, ConstBuffers (buffers), handler); + return async_handshake (role, ConstBuffers (buffers), TransferCall (handler)); } - virtual void async_handshake_impl (handshake_type role, - ConstBuffers const& buffers, TransferCall const& call) = 0; + virtual + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t)) + async_handshake (handshake_type role, BOOST_ASIO_MOVE_ARG(ConstBuffers) buffers, BOOST_ASIO_MOVE_ARG(TransferCall) call) = 0; #endif // ssl::stream::shutdown @@ -270,10 +295,12 @@ public: template void async_shutdown (BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler) { - async_shutdown_impl (handler); + return async_shutdown (ErrorCall (handler)); } - virtual void async_shutdown_impl (ErrorCall const& call) = 0; + virtual + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(ErrorCall, void (boost::system::error_code)) + async_shutdown (BOOST_ASIO_MOVE_ARG(ErrorCall) call) = 0; }; #endif diff --git a/modules/beast_asio/sockets/beast_SocketInterface.h b/modules/beast_asio/sockets/beast_SocketInterface.h index ae9d2c87c3..c320408484 100644 --- a/modules/beast_asio/sockets/beast_SocketInterface.h +++ b/modules/beast_asio/sockets/beast_SocketInterface.h @@ -31,12 +31,18 @@ struct SocketInterface /** Tag for some compatibility with asio::basic_stream_socket http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/basic_stream_socket.html */ - struct Stream { }; + struct SyncStream { }; + struct AsyncStream { }; + struct Stream : SyncStream, AsyncStream { }; - /** Tag for some compatibility with asio::ssl::stream + /** Tags for compatibility with asio::ssl::stream http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ssl__stream.html */ - struct Handshake { }; + struct SyncHandshake { }; + struct SyncBufferedHandshake : SyncHandshake { }; + struct AsyncHandshake { }; + struct AsyncBufferedHandshake : AsyncHandshake{ }; + struct Handshake : SyncBufferedHandshake, AsyncBufferedHandshake { }; }; #endif diff --git a/modules/beast_asio/sockets/beast_SocketWrapper.h b/modules/beast_asio/sockets/beast_SocketWrapper.h index 2650c490a2..b8ec2c8435 100644 --- a/modules/beast_asio/sockets/beast_SocketWrapper.h +++ b/modules/beast_asio/sockets/beast_SocketWrapper.h @@ -40,12 +40,11 @@ class SocketWrapper public: typedef Object ObjectType; typedef typename boost::remove_reference ::type ObjectT; - typedef typename boost::remove_reference ::type next_layer_type; - typedef typename next_layer_type::lowest_layer_type lowest_layer_type; - typedef boost::asio::ssl::stream_base::handshake_type handshake_type; SocketWrapper (Object& object) noexcept : m_impl (&object) + //, m_next_layer (object.next_layer ()) + //, m_lowest_layer (object.lowest_layer ()) { } @@ -71,6 +70,12 @@ public: return get_object ().get_io_service (); } + //-------------------------------------------------------------------------- + +#if 0 + typedef typename boost::remove_reference ::type next_layer_type; + typedef typename next_layer_type::lowest_layer_type lowest_layer_type; + next_layer_type& next_layer () noexcept { return get_object ().next_layer (); @@ -90,6 +95,7 @@ public: { return get_object ().lowest_layer (); } +#endif // General @@ -103,85 +109,383 @@ public: return m_impl; } - // Socket + //-------------------------------------------------------------------------- + // + // SocketInterface::Socket + // + //-------------------------------------------------------------------------- +public: boost::system::error_code cancel (boost::system::error_code& ec) { - return cancel (ec, HasInterface ()); + return cancel (ec, + HasInterface ()); } - + +private: + boost::system::error_code cancel (boost::system::error_code& ec, + boost::true_type) + { + return get_object ().cancel (ec); + } + + boost::system::error_code cancel (boost::system::error_code& ec, + boost::false_type) + { + return pure_virtual (ec); + } + +public: boost::system::error_code shutdown (shutdown_type what, boost::system::error_code& ec) { - return shutdown (what, ec, HasInterface ()); + return shutdown (what, ec, + HasInterface ()); } +private: + boost::system::error_code shutdown (Socket::shutdown_type what, boost::system::error_code& ec, + boost::true_type) + { + return get_object ().shutdown (what, ec); + } + + boost::system::error_code shutdown (Socket::shutdown_type, boost::system::error_code& ec, + boost::false_type) + { + return pure_virtual (ec); + } + +public: boost::system::error_code close (boost::system::error_code& ec) { - return close (ec, HasInterface ()); + return close (ec, + HasInterface ()); } - // Stream +private: + boost::system::error_code close (boost::system::error_code& ec, + boost::true_type) + { + return get_object ().close (ec); + } - std::size_t read_some_impl (Socket::MutableBuffers const& buffers, + boost::system::error_code close (boost::system::error_code& ec, + boost::false_type) + { + return pure_virtual (ec); + } + + //-------------------------------------------------------------------------- + // + // SocketInterface::Stream + // + //-------------------------------------------------------------------------- + +public: + std::size_t read_some (BOOST_ASIO_MOVE_ARG(MutableBuffers) buffers, boost::system::error_code& ec) { - return read_some (buffers, ec, HasInterface ()); + return read_some (buffers, ec, + HasInterface ()); } - std::size_t write_some_impl (Socket::ConstBuffers const& buffers, - boost::system::error_code& ec) +private: + template + std::size_t read_some (MutableBufferSequence const& buffers, boost::system::error_code& ec, + boost::true_type) { - return write_some (buffers, ec, HasInterface ()); + return get_object ().read_some (buffers, ec); } - void async_read_some_impl (Socket::MutableBuffers const& buffers, - TransferCall const& call) + template + std::size_t read_some (MutableBufferSequence const&, boost::system::error_code& ec, + boost::false_type) { - async_read_some (buffers, call, HasInterface ()); + pure_virtual (ec); + return 0; } - void async_write_some_impl (Socket::ConstBuffers const& buffers, - TransferCall const& call) +public: + std::size_t write_some (BOOST_ASIO_MOVE_ARG(ConstBuffers) buffers, boost::system::error_code& ec) { - async_write_some (buffers, call, HasInterface ()); + return write_some (buffers, ec, + HasInterface ()); } +private: + template + std::size_t write_some (ConstBufferSequence const& buffers, boost::system::error_code& ec, + boost::true_type) + { + return get_object ().write_some (buffers, ec); + } + + template + std::size_t write_some (ConstBufferSequence const&, boost::system::error_code& ec, + boost::false_type) + { + pure_virtual (ec); + return 0; + } + +public: + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t)) + async_read_some (BOOST_ASIO_MOVE_ARG(MutableBuffers) buffers, BOOST_ASIO_MOVE_ARG(TransferCall) call) + { + return async_read_some (buffers, call, + HasInterface ()); + } + +private: + template + BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void (boost::system::error_code, std::size_t)) + async_read_some (MutableBufferSequence const& buffers, BOOST_ASIO_MOVE_ARG(ReadHandler) handler, + boost::true_type) + { + return get_object ().async_read_some (buffers, handler); + } + + template + BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void (boost::system::error_code, std::size_t)) + async_read_some (MutableBufferSequence const&, BOOST_ASIO_MOVE_ARG(ReadHandler), + boost::false_type) + { +#if BOOST_ASIO_HAS_FUTURE_RETURNS + boost::asio::detail::async_result_init< + ReadHandler, void (boost::system::error_code, std::size_t)> init( + BOOST_ASIO_MOVE_CAST(ReadHandler)(handler)); + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec, 0)); + return init.result.get(); +#else + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec, 0)); +#endif + } + +public: + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t)) + async_write_some (BOOST_ASIO_MOVE_ARG(ConstBuffers) buffers, BOOST_ASIO_MOVE_ARG(TransferCall) call) + { + return async_write_some (buffers, call, + HasInterface ()); + } + +private: + template + BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void (boost::system::error_code, std::size_t)) + async_write_some (ConstBufferSequence const& buffers, BOOST_ASIO_MOVE_ARG(WriteHandler) handler, + boost::true_type) + { + return get_object ().async_write_some (buffers, handler); + } + + template + BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void (boost::system::error_code, std::size_t)) + async_write_some (ConstBufferSequence const&, BOOST_ASIO_MOVE_ARG(WriteHandler), + boost::false_type) + { +#if BOOST_ASIO_HAS_FUTURE_RETURNS + boost::asio::detail::async_result_init< + WriteHandler, void (boost::system::error_code, std::size_t)> init( + BOOST_ASIO_MOVE_CAST(WriteHandler)(handler)); + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec, 0)); + return init.result.get(); +#else + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec, 0)); +#endif + } + + //-------------------------------------------------------------------------- + // // Handshake + // + //-------------------------------------------------------------------------- +public: boost::system::error_code handshake (handshake_type type, boost::system::error_code& ec) { - return handshake (type, ec, HasInterface ()); + return handshake (type, ec, + HasInterface ()); } -#if (BOOST_VERSION / 100) >= 1054 - boost::system::error_code handshake_impl (handshake_type role, - Socket::ConstBuffers const& buffers, boost::system::error_code& ec) +private: + boost::system::error_code handshake (handshake_type type, boost::system::error_code& ec, + boost::true_type) { - return handshake (role, buffers, ec, HasInterface ()); - } -#endif - - void async_handshake_impl (handshake_type role, ErrorCall const& call) - { - async_handshake (role, call, HasInterface ()); - } - -#if (BOOST_VERSION / 100) >= 1054 - void async_handshake_impl (handshake_type role, - Socket::ConstBuffers const& buffers, TransferCall const& call) - { - async_handshake (role, buffers, call, HasInterface ()); + return get_object ().handshake (type, ec); + } + + boost::system::error_code handshake (handshake_type, boost::system::error_code& ec, + boost::false_type) + { + return pure_virtual (ec); + } + +public: + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(ErrorCall, void (boost::system::error_code)) + async_handshake (handshake_type type, BOOST_ASIO_MOVE_ARG(ErrorCall) call) + { + return async_handshake (type, call, + HasInterface ()); + } + +private: + template + BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, void (boost::system::error_code)) + async_handshake (handshake_type type, BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler, + boost::true_type) + { + return get_object ().async_handshake (type, handler); + } + + template + BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, void (boost::system::error_code)) + async_handshake (handshake_type, BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler, + boost::false_type) + { +#if BOOST_ASIO_HAS_FUTURE_RETURNS + boost::asio::detail::async_result_init< + HandshakeHandler, void (boost::system::error_code)> init( + BOOST_ASIO_MOVE_CAST(HandshakeHandler)(handler)); + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec)); + return init.result.get(); +#else + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec)); +#endif + } + +public: +#if BOOST_ASIO_HAS_BUFFEREDHANDSHAKE + boost::system::error_code handshake (handshake_type type, + BOOST_ASIO_MOVE_ARG(ConstBuffers) buffers, boost::system::error_code& ec) + { + return handshake (type, buffers, ec, + HasInterface ()); + } + +private: + template + boost::system::error_code handshake (handshake_type type, + ConstBufferSequence const& buffers, boost::system::error_code& ec, + boost::true_type) + { + return get_object ().handshake (type, buffers, ec); + } + + template + boost::system::error_code handshake (handshake_type, + ConstBufferSequence const&, boost::system::error_code& ec, + boost::false_type) + { + return pure_virtual (ec); + } + +public: + BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(TransferCall, void (boost::system::error_code, std::size_t)) + async_handshake (handshake_type type, BOOST_ASIO_MOVE_ARG(ConstBuffers) buffers, + BOOST_ASIO_MOVE_ARG(TransferCall) call) + { + return async_handshake (type, buffers, call, + HasInterface ()); + } + +private: + template + BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler, void (boost::system::error_code, std::size_t)) + async_handshake (handshake_type type, const ConstBufferSequence& buffers, + BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler, + boost::true_type) + { + return get_object ().async_handshake (type, buffers, handler); + } + + template + BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler, void (boost::system::error_code, std::size_t)) + async_handshake (handshake_type, const ConstBufferSequence&, + BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler, + boost::false_type) + { +#if BOOST_ASIO_HAS_FUTURE_RETURNS + boost::asio::detail::async_result_init< + BufferedHandshakeHandler, void (boost::system::error_code, std::size_t)> init( + BOOST_ASIO_MOVE_CAST(BufferedHandshakeHandler)(handler)); + boost::system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec, 0)); + return init.result.get(); +#else + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec, 0)); +#endif } #endif +public: boost::system::error_code shutdown (boost::system::error_code& ec) { - return shutdown (ec, HasInterface ()); + return shutdown (ec, + HasInterface ()); } - void async_shutdown_impl (ErrorCall const& call) +private: + boost::system::error_code shutdown (boost::system::error_code& ec, + boost::true_type) { - async_shutdown (call, HasInterface ()); + return get_object ().shutdown (ec); + } + + boost::system::error_code shutdown (boost::system::error_code& ec, + boost::false_type) + { + return pure_virtual (ec); + } + +public: + void async_shutdown (BOOST_ASIO_MOVE_ARG(ErrorCall) call) + { + async_shutdown (call, + HasInterface ()); + } + +private: + template + BOOST_ASIO_INITFN_RESULT_TYPE(ShutdownHandler, void (boost::system::error_code)) + async_shutdown (BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler, + boost::true_type) + { + return get_object ().async_shutdown (handler); + } + + template + BOOST_ASIO_INITFN_RESULT_TYPE(ShutdownHandler, void (boost::system::error_code)) + async_shutdown (BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler, + boost::false_type) + { +#if BOOST_ASIO_HAS_FUTURE_RETURNS + boost::asio::detail::async_result_init< + ShutdownHandler, void (boost::system::error_code, std::size_t)> init( + BOOST_ASIO_MOVE_CAST(ShutdownHandler)(handler)); + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec)); + return init.result.get(); +#else + system::error_code ec; + ec = pure_virtual (ec); + get_io_service ().post (boost::bind (handler, ec)); +#endif } protected: @@ -196,197 +500,16 @@ protected: } private: - static boost::system::error_code fail (boost::system::error_code const& ec = boost::system::error_code ()) + static void pure_virtual () { - fatal_error ("pure virtual"); - return ec; + fatal_error ("A beast::Socket function was called on an object that doesn't support the interface"); } - //-------------------------------------------------------------------------- - // - // Socket - // - //-------------------------------------------------------------------------- - - boost::system::error_code cancel (boost::system::error_code& ec, boost::true_type) + static boost::system::error_code pure_virtual (boost::system::error_code& ec) { - return get_object ().cancel (ec); - } - - boost::system::error_code cancel (boost::system::error_code&, boost::false_type) - { - return fail (); - } - - boost::system::error_code shutdown (Socket::shutdown_type what, boost::system::error_code& ec, boost::true_type) - { - return get_object ().shutdown (what, ec); - } - - boost::system::error_code shutdown (Socket::shutdown_type, boost::system::error_code&, boost::false_type) - { - return fail (); - } - - boost::system::error_code close (boost::system::error_code& ec, boost::true_type) - { - return get_object ().close (ec); - } - - boost::system::error_code close (boost::system::error_code&, boost::false_type) - { - return fail (); - } - - //-------------------------------------------------------------------------- - // - // Stream - // - //-------------------------------------------------------------------------- - - template - std::size_t read_some (MutableBufferSequence const& buffers, boost::system::error_code& ec, boost::true_type) - { - return get_object ().read_some (buffers, ec); - } - - template - std::size_t read_some (MutableBufferSequence const&, boost::system::error_code&, boost::false_type) - { - fail (); - return 0; - } - - template - std::size_t write_some (ConstBufferSequence const& buffers, boost::system::error_code& ec, boost::true_type) - { - return get_object ().write_some (buffers, ec); - } - - template - std::size_t write_some (ConstBufferSequence const&, boost::system::error_code&, boost::false_type) - { - fail (); - return 0; - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void (boost::system::error_code, std::size_t)) - async_read_some (MutableBufferSequence const& buffers, BOOST_ASIO_MOVE_ARG(ReadHandler) handler, boost::true_type) - { - get_object ().async_read_some (buffers, handler); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(ReadHandler, void (boost::system::error_code, std::size_t)) - async_read_some (MutableBufferSequence const&, BOOST_ASIO_MOVE_ARG(ReadHandler), boost::false_type) - { - fail (); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void (boost::system::error_code, std::size_t)) - async_write_some (ConstBufferSequence const& buffers, BOOST_ASIO_MOVE_ARG(WriteHandler) handler, boost::true_type) - { - return get_object ().async_write_some (buffers, handler); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler, void (boost::system::error_code, std::size_t)) - async_write_some (ConstBufferSequence const&, BOOST_ASIO_MOVE_ARG(WriteHandler), boost::false_type) - { - fail (); - } - - //-------------------------------------------------------------------------- - // - // Handshake - // - //-------------------------------------------------------------------------- - - boost::system::error_code handshake (handshake_type type, boost::system::error_code& ec, boost::true_type) - { - return get_object ().handshake (type, ec); - } - - boost::system::error_code handshake (handshake_type, boost::system::error_code&, boost::false_type) - { - fail (); - return boost::system::error_code (); - } - -#if (BOOST_VERSION / 100) >= 1054 - template - boost::system::error_code handshake (handshake_type type, ConstBufferSequence const& buffers, - boost::system::error_code& ec, boost::true_type) - { - return get_object ().handshake (type, buffers, ec); - } - - template - boost::system::error_code handshake (handshake_type, ConstBufferSequence const&, - boost::system::error_code&, boost::false_type) - { - fail (); - return boost::system::error_code (); - } -#endif - - template - BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, void (boost::system::error_code)) - async_handshake (handshake_type type, BOOST_ASIO_MOVE_ARG(HandshakeHandler) handler, boost::true_type) - { - return get_object ().async_handshake (type, handler); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(HandshakeHandler, void (boost::system::error_code)) - async_handshake (handshake_type, BOOST_ASIO_MOVE_ARG(HandshakeHandler), boost::false_type) - { - fail (); - } - -#if (BOOST_VERSION / 100) >= 1054 - template - BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler, void (boost::system::error_code, std::size_t)) - async_handshake (handshake_type type, const ConstBufferSequence& buffers, - BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler) handler, boost::true_type) - { - return get_object ().async_handshake (type, buffers, handler); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(BufferedHandshakeHandler, void (boost::system::error_code, std::size_t)) - async_handshake (handshake_type, const ConstBufferSequence&, - BOOST_ASIO_MOVE_ARG(BufferedHandshakeHandler), boost::false_type) - { - fail (); - } -#endif - - boost::system::error_code shutdown (boost::system::error_code& ec, boost::true_type) - { - return get_object ().shutdown (ec); - } - - boost::system::error_code shutdown (boost::system::error_code&, boost::false_type) - { - fail (); - return boost::system::error_code (); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(ShutdownHandler, void (boost::system::error_code)) - async_shutdown (BOOST_ASIO_MOVE_ARG(ShutdownHandler) handler, boost::true_type) - { - return get_object ().async_shutdown (handler); - } - - template - BOOST_ASIO_INITFN_RESULT_TYPE(ShutdownHandler, void (boost::system::error_code)) - async_shutdown (BOOST_ASIO_MOVE_ARG(ShutdownHandler), boost::false_type) - { - fail (); + pure_virtual (); + return ec = boost::system::errc::make_error_code ( + boost::system::errc::function_not_supported); } private: diff --git a/modules/beast_asio/system/beast_BoostIncludes.h b/modules/beast_asio/system/beast_BoostIncludes.h new file mode 100644 index 0000000000..98b9706729 --- /dev/null +++ b/modules/beast_asio/system/beast_BoostIncludes.h @@ -0,0 +1,81 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_BOOSTINCLUDES_H_INCLUDED +#define BEAST_BOOSTINCLUDES_H_INCLUDED + +// Make sure we take care of fixing boost::bind oddities first. +#if !defined(BEAST_CORE_H_INCLUDED) +#error beast_core.h must be included before including this file +#endif + +// These should have already been set in your project, but +// if you forgot then we will be optimistic and choose the latest. +// +#if BEAST_WIN32 +# ifndef _WIN32_WINNT +# pragma message ("Warning: _WIN32_WINNT was not set in your project") +# define _WIN32_WINNT 0x0600 +# endif +# ifndef _VARIADIC_MAX +# define _VARIADIC_MAX 10 +# endif +#endif + +#include +#include +#include +#include + +//#include +//#include +//#include +//#include +//#include +//#include + +//------------------------------------------------------------------------------ + +// Configure some options based on the version of boost +#include +#if (BOOST_VERSION / 100) >= 1054 +# define BOOST_ASIO_HAS_BUFFEREDHANDSHAKE 1 +# define BOOST_ASIO_HAS_FUTURE_RETURNS 1 +#else +# define BOOST_ASIO_HAS_BUFFEREDHANDSHAKE 0 +# define BOOST_ASIO_HAS_FUTURE_RETURNS 0 +#endif + +#if ! BOOST_ASIO_HAS_FUTURE_RETURNS +# define BOOST_ASIO_INITFN_RESULT_TYPE(expr,val) void +# define BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(expr,val) void +#else +# if defined(GENERATING_DOCUMENTATION) +# define BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(h, sig) \ + void_or_deduced +# elif defined(_MSC_VER) && (_MSC_VER < 1500) +# define BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(h, sig) \ + ::boost::asio::detail::async_result_type_helper::type +# else +# define BOOST_ASIO_INITFN_RESULT_TYPE_MEMBER(h, sig) \ + ::boost::asio::async_result <::boost::asio::handler_type::type>::type +# endif +#endif + +#endif