diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj index accc61fdc9..cc9fd8541c 100644 --- a/Builds/VisualStudio2012/beast.vcxproj +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -69,6 +69,7 @@ + diff --git a/modules/beast_asio/basics/beast_CompletionCall.h b/modules/beast_asio/basics/beast_CompletionCall.h deleted file mode 100644 index b2b89fc662..0000000000 --- a/modules/beast_asio/basics/beast_CompletionCall.h +++ /dev/null @@ -1,144 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_COMPLETIONCALL_H_INCLUDED -#define BEAST_COMPLETIONCALL_H_INCLUDED - -// Meets these requirements: -// -// CompletionHandler -// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/CompletionHandler.html -// -class CompletionCall -{ -public: - typedef void result_type; - - CompletionCall () noexcept - { - } - - // Construction from Handler with zero arguments - // - template - CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler) - : m_call (new CallType0 (BOOST_ASIO_MOVE_CAST(Handler)(handler))) - { - } - - // Creates a CompletionHandler with one parameter bound to Handler - // This can convert an ErrorCall to a CompletionCall, suitable - // for calling asio::io_service::post() - // - template - CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler, P1 p1) - : m_call (new CallType1 (BOOST_ASIO_MOVE_CAST(Handler)(handler), p1)) - { - } - - // Creates a CompletionHandler with two parameters bound to Handler - // This can convert a TransferCall to a CompletionCall, suitable - // for calling asio::io_service::post() - // - template - CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler, P1 p1, P2 p2) - : m_call (new CallType2 (BOOST_ASIO_MOVE_CAST(Handler)(handler), p1, p2)) - { - } - - CompletionCall (CompletionCall const& other) - : m_call (other.m_call) - { - } - - bool isNull () const noexcept - { - return m_call == nullptr; - } - - void operator() () - { - (*m_call) (); - } - -private: - struct Call : SharedObject, LeakChecked - { - virtual void operator() () = 0; - }; - - template - struct CallType0 : Call - { - CallType0 (BOOST_ASIO_MOVE_ARG(Handler) handler) - : m_handler (handler) - { - } - - void operator() () - { - m_handler (); - } - - Handler m_handler; - }; - - template - struct CallType1 : Call - { - CallType1 (BOOST_ASIO_MOVE_ARG(Handler) handler, P1 p1) - : m_handler (handler) - , m_p1 (p1) - { - } - - void operator() () - { - m_handler (m_p1); - } - - Handler m_handler; - P1 m_p1; - }; - - template - struct CallType2 : Call - { - CallType2 (BOOST_ASIO_MOVE_ARG(Handler) handler, P1 p1, P2 p2) - : m_handler (handler) - , m_p1 (p1) - , m_p2 (p2) - { - } - - void operator() () - { - m_handler (m_p1, m_p2); - } - - Handler m_handler; - P1 m_p1; - P2 m_p2; - }; - -private: - SharedObjectPtr m_call; -}; - -#endif diff --git a/modules/beast_asio/basics/beast_ErrorCall.h b/modules/beast_asio/basics/beast_ErrorCall.h deleted file mode 100644 index 7cca0fc17f..0000000000 --- a/modules/beast_asio/basics/beast_ErrorCall.h +++ /dev/null @@ -1,93 +0,0 @@ -//------------------------------------------------------------------------------ -/* - 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_ERRORCALL_H_INCLUDED -#define BEAST_ERRORCALL_H_INCLUDED - -// Meets these requirements: -// -// AcceptHandler -// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/AcceptHandler.html -// -// ConnectHandler -// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ConnectHandler.html -// -// ShutdownHandler -// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ShutdownHandler.html -// -// HandshakeHandler -// http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/HandshakeHandler.html -// -class ErrorCall -{ -public: - typedef void result_type; - - ErrorCall () noexcept - { - } - - template - ErrorCall (BOOST_ASIO_MOVE_ARG(Handler) handler) - : m_call (new CallType (BOOST_ASIO_MOVE_CAST(Handler)(handler))) - { - } - - ErrorCall (ErrorCall const& other) - : m_call (other.m_call) - { - } - - bool isNull () const noexcept - { - return m_call == nullptr; - } - - void operator() (boost::system::error_code const& ec) - { - (*m_call) (ec); - } - -private: - struct Call : SharedObject, LeakChecked - { - virtual void operator() (boost::system::error_code const&) = 0; - }; - - template - struct CallType : Call - { - CallType (BOOST_ASIO_MOVE_ARG(Handler) handler) - : m_handler (handler) - { - } - - void operator() (boost::system::error_code const& ec) - { - m_handler (ec); - } - - Handler m_handler; - }; - -private: - SharedObjectPtr m_call; -}; - -#endif diff --git a/modules/beast_asio/basics/beast_HandlerCall.h b/modules/beast_asio/basics/beast_HandlerCall.h new file mode 100644 index 0000000000..c5282fa0b2 --- /dev/null +++ b/modules/beast_asio/basics/beast_HandlerCall.h @@ -0,0 +1,703 @@ +//------------------------------------------------------------------------------ +/* + 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_HANDLERCALL_H_INCLUDED +#define BEAST_HANDLERCALL_H_INCLUDED + +/** A polymorphic Handler that can wrap any other handler. + + This is very lightweight container that just holds a shared pointer + to the actual handler. This means it can be copied cheaply. The + allocation and deallocation of the handler is performed according + to the requirements of asio_handler_allocate and asio_handler_delete. + All calls also satisfy the safety guarantees of asio_handler_invoke. + + All constructors will take ownership of the passed in handler + if your compiler has MoveConstructible and MoveAssignable support enabled. + + Supports these concepts: + DefaultConstructible + MoveConstructible (C++11) + CopyConstructible + MoveAssignable (C++11) + CopyAssignable + Destructible +*/ +class HandlerCall +{ +private: + typedef boost::system::error_code error_code; + +public: + typedef void result_type; + + // Really there are only 3 kings of functions. + // Except for the composed connect, which we haven't done yet. + // + struct Post { }; // void() + struct Error { }; // void(error_code) + struct Transfer { }; // void(error_code, std::size_t) + + // These tags tell us what kind of Handler we have. + // It would be nice if we could deduce this, but the + // return value of a bind() seems to satisfy the + // requirements of ANY handler so that was scrapped. + + // CompletionHandler + // + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/CompletionHandler.html + // + typedef Post Completion; + + // AcceptHandler + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/AcceptHandler.html + // + typedef Error Accept; + + // ConnectHandler + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ConnectHandler.html + // + typedef Error Connect; + + // ShutdownHandler + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ShutdownHandler.html + // + typedef Error Shutdown; + + // HandshakeHandler + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/HandshakeHandler.html + // + typedef Error Handshake; + + // ReadHandler + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/ReadHandler.html + // + typedef Transfer Read; + + // WriteHandler + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/WriteHandler.html + // + typedef Transfer Write; + + // BufferedHandshakeHandler + // http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference/BufferedHandshakeHandler.html + // + typedef Transfer BufferedHandshake; + + //-------------------------------------------------------------------------- + + HandlerCall () noexcept + { + } + + template + HandlerCall (BOOST_ASIO_MOVE_ARG(Handler) handler, Completion) + : m_call (construct ( + BOOST_ASIO_MOVE_CAST(Handler)(handler))) + { + } + + template + HandlerCall (BOOST_ASIO_MOVE_ARG(Handler) handler, Arg1 arg1, Completion) + : m_call (construct ( + BOOST_ASIO_MOVE_CAST(Handler)(handler), arg1)) + { + } + + template + HandlerCall (BOOST_ASIO_MOVE_ARG(Handler) handler, Arg1 arg1, Arg2 arg2, Completion) + : m_call (construct ( + BOOST_ASIO_MOVE_CAST(Handler)(handler), arg1, arg2)) + { + } + + template + HandlerCall (BOOST_ASIO_MOVE_ARG(Handler) handler, Error) + : m_call (construct ( + BOOST_ASIO_MOVE_CAST(Handler)(handler))) + + { + } + + template + HandlerCall (BOOST_ASIO_MOVE_ARG(Handler) handler, Transfer) + : m_call (construct ( + BOOST_ASIO_MOVE_CAST(Handler)(handler))) + { + } + + inline HandlerCall (HandlerCall const& other) noexcept + : m_call (other.m_call) + { + } + + inline HandlerCall& operator= (HandlerCall const& other) noexcept + { + m_call = other.m_call; + return *this; + } + +#if BEAST_COMPILER_SUPPORTS_MOVE_SEMANTICS + inline HandlerCall (HandlerCall && other) noexcept + : m_call (other.m_call) + { + other.m_call = nullptr; + } + + inline HandlerCall& operator= (HandlerCall&& other) noexcept + { + m_call = other.m_call; + other.m_call = nullptr; + return *this; + } +#endif + + inline bool isNull () const noexcept + { + return m_call == nullptr; + } + + inline bool isNotNull () const noexcept + { + return m_call != nullptr; + } + + inline void operator() () + { + (*m_call)(); + } + + inline void operator() (error_code const& ec) + { + (*m_call)(ec); + } + + inline void operator() (error_code const& ec, std::size_t bytes_transferred) + { + (*m_call)(ec, bytes_transferred); + } + +private: + + //-------------------------------------------------------------------------- + // + // Implementation + // + //-------------------------------------------------------------------------- + + struct Call; + + // These construct the reference counted polymorphic wrapper (Call) + // around the handler. We use MoveAssignable (rvalue-references) + // assignments to take ownership of the object and bring it to our stack. + // From there, we use the context's hooked allocation function to create + // a single piece of memory to hold our wrapper. Then we use placement + // new to construct the wrapper. The wrapper uses rvalue assignment + // to take ownership of the handler from the stack. + + template