diff --git a/beast/asio/Asio.unity.cpp b/beast/asio/Asio.unity.cpp index dbe4b458df..ed38fcdd12 100644 --- a/beast/asio/Asio.unity.cpp +++ b/beast/asio/Asio.unity.cpp @@ -22,11 +22,5 @@ #endif #include - -#include #include -#include -#include - -#include // TEMPORARY! diff --git a/beast/asio/abstract_socket.cpp b/beast/asio/abstract_socket.cpp deleted file mode 100644 index dfd542db5a..0000000000 --- a/beast/asio/abstract_socket.cpp +++ /dev/null @@ -1,217 +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. -*/ -//============================================================================== - -#include -#include - -namespace beast { -namespace asio { - -#if ! BEAST_COMPILER_CHECKS_SOCKET_OVERRIDES - -//------------------------------------------------------------------------------ -// -// Socket -// -//------------------------------------------------------------------------------ - -void* abstract_socket::this_layer_ptr (char const*) const -{ - pure_virtual_called (); - return nullptr; -} - -//------------------------------------------------------------------------------ -// -// native_handle -// -//------------------------------------------------------------------------------ - -bool abstract_socket::native_handle (char const*, void*) -{ - pure_virtual_called (); - return false; -} - -//------------------------------------------------------------------------------ -// -// basic_io_object -// -//------------------------------------------------------------------------------ - -boost::asio::io_service& abstract_socket::get_io_service () -{ - pure_virtual_called (); - return *static_cast (nullptr); -} - -//------------------------------------------------------------------------------ -// -// basic_socket -// -//------------------------------------------------------------------------------ - -void* -abstract_socket::lowest_layer_ptr (char const*) const -{ - pure_virtual_called (); - return nullptr; -} - -auto -abstract_socket::cancel (boost::system::error_code& ec) -> error_code -{ - return pure_virtual_error (ec); -} - -auto -abstract_socket::shutdown (shutdown_type, boost::system::error_code& ec) -> error_code -{ - return pure_virtual_error (ec); -} - -auto -abstract_socket::close (boost::system::error_code& ec) -> error_code -{ - return pure_virtual_error (ec); -} - -//------------------------------------------------------------------------------ -// -// basic_socket_acceptor -// -//------------------------------------------------------------------------------ - -auto -abstract_socket::accept (abstract_socket&, error_code& ec) -> error_code -{ - return pure_virtual_error (ec); -} - -void -abstract_socket::async_accept (abstract_socket&, error_handler handler) -{ - get_io_service ().post (bind_handler ( - handler, pure_virtual_error())); -} - -//------------------------------------------------------------------------------ -// -// basic_stream_socket -// -//------------------------------------------------------------------------------ - -std::size_t -abstract_socket::read_some (mutable_buffers, error_code& ec) -{ - ec = pure_virtual_error (); - return 0; -} - -std::size_t -abstract_socket::write_some (const_buffers, error_code& ec) -{ - ec = pure_virtual_error (); - return 0; -} - -void -abstract_socket::async_read_some (mutable_buffers, transfer_handler handler) -{ - get_io_service ().post (bind_handler ( - handler, pure_virtual_error(), 0)); -} - -void -abstract_socket::async_write_some (const_buffers, transfer_handler handler) -{ - get_io_service ().post (bind_handler ( - handler, pure_virtual_error(), 0)); -} - -//------------------------------------------------------------------------------ -// -// ssl::stream -// -//------------------------------------------------------------------------------ - -void* -abstract_socket::next_layer_ptr (char const*) const -{ - pure_virtual_called (); - return nullptr; -} - -bool -abstract_socket::needs_handshake () -{ - return false; -} - -void -abstract_socket::set_verify_mode (int) -{ - pure_virtual_called (); -} - -auto -abstract_socket::handshake (handshake_type, error_code& ec) -> error_code -{ - return pure_virtual_error (ec); -} - -void -abstract_socket::async_handshake (handshake_type, error_handler handler) -{ - get_io_service ().post (bind_handler ( - handler, pure_virtual_error())); -} - -auto -abstract_socket::handshake (handshake_type, const_buffers, error_code& ec) -> - error_code -{ - return pure_virtual_error (ec); -} - -void -abstract_socket::async_handshake (handshake_type, const_buffers, - transfer_handler handler) -{ - get_io_service ().post (bind_handler ( - handler, pure_virtual_error(), 0)); -} - -auto -abstract_socket::shutdown (error_code& ec) -> error_code -{ - return pure_virtual_error (ec); -} - -void -abstract_socket::async_shutdown (error_handler handler) -{ - get_io_service ().post (bind_handler ( - handler, pure_virtual_error())); -} - -#endif - -} -} diff --git a/beast/asio/abstract_socket.h b/beast/asio/abstract_socket.h deleted file mode 100644 index ef2b1dba9c..0000000000 --- a/beast/asio/abstract_socket.h +++ /dev/null @@ -1,404 +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_ASIO_ABSTRACT_SOCKET_H_INCLUDED -#define BEAST_ASIO_ABSTRACT_SOCKET_H_INCLUDED - -#include -#include -#include -#include -#include - -// Checking overrides replaces unimplemented stubs with pure virtuals -#ifndef BEAST_COMPILER_CHECKS_SOCKET_OVERRIDES -# define BEAST_COMPILER_CHECKS_SOCKET_OVERRIDES 1 -#endif - -#if BEAST_COMPILER_CHECKS_SOCKET_OVERRIDES -# define BEAST_SOCKET_VIRTUAL = 0 -#else -# define BEAST_SOCKET_VIRTUAL -#endif - -namespace beast { -namespace asio { - -/** A high level socket abstraction. - - This combines the capabilities of multiple socket interfaces such - as listening, connecting, streaming, and handshaking. It brings - everything together into a single abstract interface. - - When member functions are called and the underlying implementation does - not support the operation, a fatal error is generated. -*/ -class abstract_socket - : public boost::asio::ssl::stream_base - , public boost::asio::socket_base -{ -protected: - typedef boost::system::error_code error_code; - - typedef asio::shared_handler post_handler; - - typedef asio::shared_handler error_handler; - - typedef asio::shared_handler < - void (error_code, std::size_t)> transfer_handler; - - static - void - pure_virtual_called() - { - throw std::runtime_error ("pure virtual called"); - } - - static - error_code - pure_virtual_error () - { - pure_virtual_called(); - return boost::system::errc::make_error_code ( - boost::system::errc::function_not_supported); - } - - static - error_code - pure_virtual_error (error_code& ec) - { - return ec = pure_virtual_error(); - } - - static - void - throw_if (error_code const& ec) - { - if (ec) - throw boost::system::system_error (ec); - } - -public: - virtual ~abstract_socket () - { - } - - //-------------------------------------------------------------------------- - // - // abstract_socket - // - //-------------------------------------------------------------------------- - - /** Retrieve the underlying object. - - @note If the type doesn't match, nullptr is returned or an - exception is thrown if trying to acquire a reference. - */ - /** @{ */ - template - Object& this_layer () - { - Object* object (this->this_layer_ptr ()); - if (object == nullptr) - throw std::bad_cast (); - return *object; - } - - template - Object const& this_layer () const - { - Object const* object (this->this_layer_ptr ()); - if (object == nullptr) - throw std::bad_cast (); - return *object; - } - - template - Object* this_layer_ptr () - { - return static_cast ( - this->this_layer_ptr (typeid (Object).name ())); - } - - template - Object const* this_layer_ptr () const - { - return static_cast ( - this->this_layer_ptr (typeid (Object).name ())); - } - /** @} */ - - virtual void* this_layer_ptr (char const* type_name) const - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - // - // native_handle - // - //-------------------------------------------------------------------------- - - /** Retrieve the native representation of the object. - - Since we dont know the return type, and because almost every - asio implementation passes the result by value, you need to provide - a pointer to a default-constructed object of the matching type. - - @note If the type doesn't match, an exception is thrown. - */ - template - void native_handle (Handle* dest) - { - if (! native_handle (typeid (Handle).name (), dest)) - throw std::bad_cast (); - } - - virtual bool native_handle (char const* type_name, void* dest) - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - // - // basic_io_object - // - //-------------------------------------------------------------------------- - - virtual boost::asio::io_service& get_io_service () - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - // - // basic_socket - // - //-------------------------------------------------------------------------- - - /** Retrieve the lowest layer object. - - @note If the type doesn't match, nullptr is returned or an - exception is thrown if trying to acquire a reference. - */ - /** @{ */ - template - Object& lowest_layer () - { - Object* object (this->lowest_layer_ptr ()); - if (object == nullptr) - throw std::bad_cast (); - return *object; - } - - template - Object const& lowest_layer () const - { - Object const* object (this->lowest_layer_ptr ()); - if (object == nullptr) - throw std::bad_cast (); - return *object; - } - - template - Object* lowest_layer_ptr () - { - return static_cast ( - this->lowest_layer_ptr (typeid (Object).name ())); - } - - template - Object const* lowest_layer_ptr () const - { - return static_cast ( - this->lowest_layer_ptr (typeid (Object).name ())); - } - /** @} */ - - virtual void* lowest_layer_ptr (char const* type_name) const - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - - void cancel () - { - error_code ec; - cancel (ec); - throw_if (ec); - } - - virtual error_code cancel (error_code& ec) - BEAST_SOCKET_VIRTUAL; - - void shutdown (shutdown_type what) - { - error_code ec; - shutdown (what, ec); - throw_if (ec); - } - - virtual error_code shutdown (shutdown_type what, - error_code& ec) - BEAST_SOCKET_VIRTUAL; - - void close () - { - error_code ec; - close (ec); - throw_if (ec); - } - - virtual error_code close (error_code& ec) - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - // - // basic_socket_acceptor - // - //-------------------------------------------------------------------------- - - virtual error_code accept (abstract_socket& peer, error_code& ec) - BEAST_SOCKET_VIRTUAL; - - virtual void async_accept (abstract_socket& peer, error_handler handler) - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - // - // basic_stream_socket - // - //-------------------------------------------------------------------------- - - virtual std::size_t read_some (mutable_buffers buffers, error_code& ec) - BEAST_SOCKET_VIRTUAL; - - virtual std::size_t write_some (const_buffers buffers, error_code& ec) - BEAST_SOCKET_VIRTUAL; - - virtual void async_read_some (mutable_buffers buffers, - transfer_handler handler) - BEAST_SOCKET_VIRTUAL; - - virtual void async_write_some (const_buffers buffers, - transfer_handler handler) - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - // - // ssl::stream - // - //-------------------------------------------------------------------------- - - /** Retrieve the next layer object. - - @note If the type doesn't match, nullptr is returned or an - exception is thrown if trying to acquire a reference. - */ - /** @{ */ - template - Object& next_layer () - { - Object* object (this->next_layer_ptr ()); - if (object == nullptr) - throw std::bad_cast (); - return *object; - } - - template - Object const& next_layer () const - { - Object const* object (this->next_layer_ptr ()); - if (object == nullptr) - throw std::bad_cast (); - return *object; - } - - template - Object* next_layer_ptr () - { - return static_cast ( - this->next_layer_ptr (typeid (Object).name ())); - } - - template - Object const* next_layer_ptr () const - { - return static_cast ( - this->next_layer_ptr (typeid (Object).name ())); - } - /** @} */ - - virtual void* next_layer_ptr (char const* type_name) const - BEAST_SOCKET_VIRTUAL; - - /** Determines if the underlying stream requires a handshake. - - 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 - socket or else the closure will not be graceful. Only one side should - initiate the handshaking shutdon. The other side should observe it. - Which side does what is up to the user. - - The default version returns false. - */ - virtual bool needs_handshake () - BEAST_SOCKET_VIRTUAL; - - virtual void set_verify_mode (int verify_mode) - BEAST_SOCKET_VIRTUAL; - - void handshake (handshake_type type) - { - error_code ec; - handshake (type, ec); - throw_if (ec); - } - - virtual error_code handshake (handshake_type type, error_code& ec) - BEAST_SOCKET_VIRTUAL; - - virtual void async_handshake (handshake_type type, error_handler handler) - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - - virtual error_code handshake (handshake_type type, - const_buffers buffers, error_code& ec) - BEAST_SOCKET_VIRTUAL; - - virtual void async_handshake (handshake_type type, - const_buffers buffers, transfer_handler handler) - BEAST_SOCKET_VIRTUAL; - - //-------------------------------------------------------------------------- - - void shutdown () - { - error_code ec; - shutdown (ec); - throw_if (ec); - } - - virtual error_code shutdown (error_code& ec) - BEAST_SOCKET_VIRTUAL; - - virtual void async_shutdown (error_handler handler) - BEAST_SOCKET_VIRTUAL; -}; - -} -} - -#endif diff --git a/beast/asio/buffer_sequence.h b/beast/asio/buffer_sequence.h deleted file mode 100644 index d2259eba62..0000000000 --- a/beast/asio/buffer_sequence.h +++ /dev/null @@ -1,126 +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_ASIO_BUFFER_SEQUENCE_H_INCLUDED -#define BEAST_ASIO_BUFFER_SEQUENCE_H_INCLUDED - -#include - -#include -#include -#include -#include // -#include - -namespace beast { -namespace asio { - -template -class buffer_sequence -{ -private: - typedef std::vector sequence_type; - -public: - typedef Buffer value_type; - typedef typename sequence_type::const_iterator const_iterator; - -private: - sequence_type m_buffers; - - template - void assign (FwdIter first, FwdIter last) - { - m_buffers.clear(); - m_buffers.reserve (std::distance (first, last)); - for (;first != last; ++first) - m_buffers.push_back (*first); - } - -public: - buffer_sequence () - { - } - - template < - class BufferSequence, - class = std::enable_if_t ::value> - > - buffer_sequence (BufferSequence const& s) - { - assign (std::begin (s), std::end (s)); - } - - template < - class FwdIter, - class = std::enable_if_t ::value_type>::value> - > - buffer_sequence (FwdIter first, FwdIter last) - { - assign (first, last); - } - - template - std::enable_if_t ::value, - buffer_sequence& - > - operator= (BufferSequence const& s) - { - return assign (s); - } - - const_iterator - begin () const noexcept - { - return m_buffers.begin (); - } - - const_iterator - end () const noexcept - { - return m_buffers.end (); - } - -#if 0 - template - void - assign (ConstBufferSequence const& buffers) - { - auto const n (std::distance ( - std::begin (buffers), std::end (buffers))); - - for (int i = 0, auto iter (std::begin (buffers)); - iter != std::end (buffers); ++iter, ++i) - m_buffers[i] = Buffer (boost::asio::buffer_cast ( - *iter), boost::asio::buffer_size (*iter)); - } -#endif -}; - -typedef buffer_sequence const_buffers; -typedef buffer_sequence mutable_buffers; - -} -} - -#endif diff --git a/beast/asio/enable_wait_for_async.h b/beast/asio/enable_wait_for_async.h deleted file mode 100644 index 84f163b410..0000000000 --- a/beast/asio/enable_wait_for_async.h +++ /dev/null @@ -1,369 +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_ASIO_ENABLE_WAIT_FOR_ASYNC_H_INCLUDED -#define BEAST_ASIO_ENABLE_WAIT_FOR_ASYNC_H_INCLUDED - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // - -namespace beast { -namespace asio { - -namespace detail { - -template -class ref_counted_wrapped_handler -{ -private: - static_assert (std::is_same , Owner>::value, - "Owner cannot be a const or reference type"); - - Handler m_handler; - std::reference_wrapper m_owner; - bool m_continuation; - -public: - ~ref_counted_wrapped_handler(); - - ref_counted_wrapped_handler (Owner& owner, - Handler&& handler, bool continuation); - - ref_counted_wrapped_handler (Owner& owner, - Handler const& handler, bool continuation); - - ref_counted_wrapped_handler ( - ref_counted_wrapped_handler const& other); - - ref_counted_wrapped_handler ( - ref_counted_wrapped_handler&& other); - - ref_counted_wrapped_handler& operator= ( - ref_counted_wrapped_handler const&) = delete; - - template - void - operator() (Args&&... args) - { - m_handler (std::forward (args)...); - } - - template - void - operator() (Args&&... args) const - { - m_handler (std::forward (args)...); - } - - template - friend - void - asio_handler_invoke (Function& f, - ref_counted_wrapped_handler* h) - { - boost_asio_handler_invoke_helpers:: - invoke (f, h->m_handler); - } - - template - friend - void - asio_handler_invoke (Function const& f, - ref_counted_wrapped_handler* h) - { - boost_asio_handler_invoke_helpers:: - invoke (f, h->m_handler); - } - - friend - void* - asio_handler_allocate (std::size_t size, - ref_counted_wrapped_handler* h) - { - return boost_asio_handler_alloc_helpers:: - allocate (size, h->m_handler); - } - - friend - void - asio_handler_deallocate (void* p, std::size_t size, - ref_counted_wrapped_handler* h) - { - boost_asio_handler_alloc_helpers:: - deallocate (p, size, h->m_handler); - } - - friend - bool - asio_handler_is_continuation (ref_counted_wrapped_handler* h) - { - return h->m_continuation; - } -}; - -template -ref_counted_wrapped_handler::~ref_counted_wrapped_handler() -{ - m_owner.get().decrement(); -} - -template -ref_counted_wrapped_handler::ref_counted_wrapped_handler ( - Owner& owner, Handler&& handler, bool continuation) - : m_handler (std::move (handler)) - , m_owner (owner) - , m_continuation (continuation ? true : - boost_asio_handler_cont_helpers::is_continuation (m_handler)) -{ - m_owner.get().increment(); -} - -template -ref_counted_wrapped_handler::ref_counted_wrapped_handler ( - Owner& owner, Handler const& handler, bool continuation) - : m_handler (handler) - , m_owner (owner) - , m_continuation (continuation ? true : - boost_asio_handler_cont_helpers::is_continuation (m_handler)) -{ - m_owner.get().increment(); -} - -template -ref_counted_wrapped_handler::ref_counted_wrapped_handler ( - ref_counted_wrapped_handler const& other) - : m_handler (other.m_handler) - , m_owner (other.m_owner) - , m_continuation (other.m_continuation) -{ - m_owner.get().increment(); -} - -template -ref_counted_wrapped_handler::ref_counted_wrapped_handler ( - ref_counted_wrapped_handler&& other) - : m_handler (std::move (other.m_handler)) - , m_owner (other.m_owner) - , m_continuation (other.m_continuation) -{ - m_owner.get().increment(); -} - -} - -//------------------------------------------------------------------------------ - -/** Facilitates blocking until no completion handlers are remaining. - If Derived has this member function: - - @code - void on_wait_for_async (void) - @endcode - - Then it will be called every time the number of pending completion - handlers transitions to zero from a non-zero value. The call is made - while holding the internal mutex. -*/ -template -class enable_wait_for_async -{ -private: - BEAST_DEFINE_IS_CALL_POSSIBLE( - has_on_wait_for_async,on_wait_for_async); - - void increment() - { - std::lock_guard lock (m_mutex); - ++m_count; - } - - void notify (std::true_type) - { - static_cast (this)->on_wait_for_async(); - } - - void notify (std::false_type) - { - } - - void decrement() - { - std::lock_guard lock (m_mutex); - --m_count; - if (m_count == 0) - { - m_cond.notify_all(); - notify (std::integral_constant ::value>()); - } - } - - template - friend class detail::ref_counted_wrapped_handler; - - std::mutex m_mutex; - std::condition_variable m_cond; - std::size_t m_count; - -public: - /** Blocks if there are any pending completion handlers. */ - void - wait_for_async() - { - std::unique_lock lock (m_mutex); - while (m_count != 0) - m_cond.wait (lock); - } - -protected: - enable_wait_for_async() - : m_count (0) - { - } - - ~enable_wait_for_async() - { - assert (m_count == 0); - } - - /** Wraps the specified handler so it can be counted. */ - /** @{ */ - template - detail::ref_counted_wrapped_handler < - enable_wait_for_async, - std::remove_reference_t - > - wrap_with_counter (Handler&& handler, bool continuation = false) - { - return detail::ref_counted_wrapped_handler > (*this, - std::forward (handler), continuation); - } - - template - detail::ref_counted_wrapped_handler < - enable_wait_for_async, - std::remove_reference_t - > - wrap_with_counter (continuation_t, Handler&& handler) - { - return detail::ref_counted_wrapped_handler > (*this, - std::forward (handler), true); - } - /** @} */ -}; - -//------------------------------------------------------------------------------ - -/** A waitable event object that blocks when handlers are pending. */ -class pending_handlers -{ -private: - std::size_t count_ = 0; - std::mutex mutex_; - std::condition_variable cond_; - - template - friend class detail::ref_counted_wrapped_handler; - - template - void - increment(); - - template - void - decrement(); - -public: - ~pending_handlers() - { - assert (count_ == 0); - } - - template - void - wait(); - - /** Returns a handler that causes wait to block until completed. - The returned handler provides the same execution - guarantees as the passed handler. - */ - /** @{ */ - template - detail::ref_counted_wrapped_handler > - wrap (Handler&& handler, - bool continuation = false) - { - return detail::ref_counted_wrapped_handler > (*this, - std::forward(handler), continuation); - } - - template - detail::ref_counted_wrapped_handler > - wrap (continuation_t, Handler&& handler) - { - return detail::ref_counted_wrapped_handler > (*this, - std::forward(handler), true); - } - /** @} */ -}; - -template -void -pending_handlers::increment() -{ - std::lock_guard lock (mutex_); - ++count_; -} - -template -void -pending_handlers::decrement() -{ - std::lock_guard lock (mutex_); - if (--count_ == 0) - cond_.notify_all(); -} - -template -void -pending_handlers::wait() -{ - std::unique_lock lock (mutex_); - while (count_ != 0) - cond_.wait (lock); -} - -} -} - -#endif diff --git a/beast/asio/memory_buffer.h b/beast/asio/memory_buffer.h deleted file mode 100644 index f775687833..0000000000 --- a/beast/asio/memory_buffer.h +++ /dev/null @@ -1,426 +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_ASIO_MEMORY_BUFFER_H_INCLUDED -#define BEAST_ASIO_MEMORY_BUFFER_H_INCLUDED - -#include - -#include - -#include -#include -#include -#include - -namespace beast { -namespace asio { - -template < - class T, - class Alloc = std::allocator -> -class memory_buffer - : private empty_base_optimization -{ -private: - static_assert (std::is_same ::value || - std::is_same ::value, - "memory_buffer only works with char and unsigned char"); - - typedef empty_base_optimization Base; - - using AllocTraits = std::allocator_traits ; - - T* m_base; - std::size_t m_size; - -public: - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - typedef T& reference; - typedef T const& const_reference; - typedef T* pointer; - typedef T const* const_pointer; - typedef Alloc allocator_type; - typedef T* iterator; - typedef T const* const_iterator; - typedef std::reverse_iterator reverse_iterator; - typedef std::reverse_iterator const_reverse_iterator; - - memory_buffer () - : m_base (nullptr) - , m_size (0) - { - } - - memory_buffer (memory_buffer&& other) - : Base (std::move (other)) - , m_base (other.m_base) - , m_size (other.m_size) - { - other.m_base = nullptr; - other.m_size = 0; - } - - explicit memory_buffer (size_type n) - : m_base (AllocTraits::allocate (Base::member(), n)) - , m_size (n) - { - } - - explicit memory_buffer (Alloc const& alloc) - : Base (alloc) - , m_base (nullptr) - , m_size (0) - { - } - - memory_buffer (size_type n, Alloc const& alloc) - : Base (alloc) - , m_base (AllocTraits::allocate (Base::member(), n)) - , m_size (n) - { - } - - ~memory_buffer() - { - if (m_base != nullptr) - AllocTraits::deallocate (Base::member(), m_base, m_size); - } - - memory_buffer& operator= (memory_buffer const&) = delete; - - allocator_type - get_allocator() const - { - return Base::member; - } - - // - // asio support - // - - boost::asio::mutable_buffer - buffer() - { - return boost::asio::mutable_buffer ( - data(), bytes()); - } - - boost::asio::const_buffer - buffer() const - { - return boost::asio::const_buffer ( - data(), bytes()); - } - - boost::asio::mutable_buffers_1 - buffers() - { - return boost::asio::mutable_buffers_1 ( - data(), bytes()); - } - - boost::asio::const_buffers_1 - buffers() const - { - return boost::asio::const_buffers_1 ( - data(), bytes()); - } - - operator boost::asio::mutable_buffer() - { - return buffer(); - } - - operator boost::asio::const_buffer() const - { - return buffer(); - } - - operator boost::asio::mutable_buffers_1() - { - return buffers(); - } - - operator boost::asio::const_buffers_1() const - { - return buffers(); - } - - // - // Element access - // - - reference - at (size_type pos) - { - if (! (pos < size())) - throw std::out_of_range ("bad array index"); - return m_base [pos]; - } - - const_reference - at (size_type pos) const - { - if (! (pos < size())) - throw std::out_of_range ("bad array index"); - return m_base [pos]; - } - - reference - operator[] (size_type pos) noexcept - { - return m_base [pos]; - } - - const_reference - operator[] (size_type pos) const noexcept - { - return m_base [pos]; - } - - reference - back() noexcept - { - return m_base [m_size - 1]; - } - - const_reference - back() const noexcept - { - return m_base [m_size - 1]; - } - - reference - front() noexcept - { - return *m_base; - } - - const_reference - front() const noexcept - { - return *m_base; - } - - pointer - data() noexcept - { - return m_base; - } - - const_pointer - data() const noexcept - { - return m_base; - } - - // - // Iterators - // - - iterator - begin() noexcept - { - return m_base; - } - - const_iterator - begin() const noexcept - { - return m_base; - } - - const_iterator - cbegin() const noexcept - { - return m_base; - } - - iterator - end() noexcept - { - return m_base + m_size; - } - - const_iterator - end() const noexcept - { - return m_base + m_size; - } - - const_iterator - cend() const noexcept - { - return m_base + m_size; - } - - reverse_iterator - rbegin() noexcept - { - return reverse_iterator (end()); - } - - const_reverse_iterator - rbegin() const noexcept - { - return const_reverse_iterator (cend()); - } - - const_reverse_iterator - crbegin() const noexcept - { - return const_reverse_iterator (cend()); - } - - reverse_iterator - rend() noexcept - { - return reverse_iterator (begin()); - } - - const_reverse_iterator - rend() const noexcept - { - return const_reverse_iterator (cbegin()); - } - - const_reverse_iterator - crend() const noexcept - { - return const_reverse_iterator (cbegin()); - } - - // - // Capacity - // - - bool - empty() const noexcept - { - return m_size == 0; - } - - size_type - size() const noexcept - { - return m_size; - } - - size_type - max_size() const noexcept - { - return size(); - } - - size_type - capacity() const noexcept - { - return size(); - } - - size_type bytes() const - { - return m_size * sizeof(T); - } - - // - // Modifiers - // - - template - friend - void - swap (memory_buffer & lhs, - memory_buffer & rhs) noexcept; -}; - -//------------------------------------------------------------------------------ - -template -void -swap (memory_buffer & lhs, - memory_buffer & rhs) noexcept -{ - std::swap (lhs.m_base, rhs.m_base); - std::swap (lhs.m_size, rhs.m_size); -} - -template -inline -bool -operator== (memory_buffer const& lhs, - memory_buffer const& rhs) -{ - return std::equal (lhs.cbegin(), lhs.cend(), - rhs.cbegin(), rhs.cend()); -} - -template -inline -bool -operator!= (memory_buffer const& lhs, - memory_buffer const& rhs) -{ - return ! (lhs == rhs); -} - -template -inline -bool -operator< (memory_buffer const& lhs, - memory_buffer const& rhs) -{ - return std::lexicographical_compare ( - lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend()); -} - -template -inline -bool -operator>= (memory_buffer const& lhs, - memory_buffer const& rhs) -{ - return ! (lhs < rhs); -} - -template -inline -bool -operator> (memory_buffer const& lhs, - memory_buffer const& rhs) -{ - return rhs < lhs; -} - -template -inline -bool -operator<= (memory_buffer const& lhs, - memory_buffer const& rhs) -{ - return ! (rhs < lhs); -} - -} -} - -#endif diff --git a/beast/asio/shared_handler.h b/beast/asio/shared_handler.h deleted file mode 100644 index bc8a149a3b..0000000000 --- a/beast/asio/shared_handler.h +++ /dev/null @@ -1,475 +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_ASIO_SHARED_HANDLER_H_INCLUDED -#define BEAST_ASIO_SHARED_HANDLER_H_INCLUDED - -#include - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include // - -#ifndef BEAST_ASIO_NO_ALLOCATE_SHARED -#define BEAST_ASIO_NO_ALLOCATE_SHARED 0 -#endif - -#ifndef BEAST_ASIO_NO_HANDLER_RESULT_OF -#define BEAST_ASIO_NO_HANDLER_RESULT_OF 1 -#endif - -namespace beast { -namespace asio { - -class shared_handler_wrapper_base -{ -public: - virtual ~shared_handler_wrapper_base() - { - } - - virtual void invoke (std::function f) = 0; - virtual void* allocate (std::size_t size) = 0; - virtual void deallocate (void* p, std::size_t size) = 0; - virtual bool is_continuation () = 0; -}; - -//------------------------------------------------------------------------------ - -template -class shared_handler_wrapper_func - : public shared_handler_wrapper_base -{ -private: - std::function m_func; - -public: - template - explicit shared_handler_wrapper_func (Handler&& handler) - : m_func (std::ref (std::forward (handler))) - { - } - - template -#if BEAST_ASIO_NO_HANDLER_RESULT_OF - void -#else - std::result_of_t (Args...)> -#endif - operator() (Args&&... args) const - { - return m_func (std::forward (args)...); - } -}; - -//------------------------------------------------------------------------------ - -namespace detail { - -#ifdef _MSC_VER -#pragma warning (push) -#pragma warning (disable: 4512) // assignment operator could not be generated -#endif - -template -class shared_handler_wrapper - : private boost::base_from_member - , public shared_handler_wrapper_func -{ -private: - typedef boost::base_from_member Base; - - BEAST_DEFINE_IS_CALL_POSSIBLE(has_is_continuation, is_continuation); - -public: - shared_handler_wrapper (Handler&& handler) - : boost::base_from_member (std::move (handler)) - , shared_handler_wrapper_func (Base::member) - { - } - - shared_handler_wrapper (Handler const& handler) - : boost::base_from_member (handler) - , shared_handler_wrapper_func (Base::member) - { - } - -private: - void - invoke (std::function f) override - { - return boost_asio_handler_invoke_helpers:: - invoke (f, Base::member); - } - - void* - allocate (std::size_t size) override - { - return boost_asio_handler_alloc_helpers:: - allocate (size, Base::member); - } - - void - deallocate (void* p, std::size_t size) override - { - boost_asio_handler_alloc_helpers:: - deallocate (p, size, Base::member); - } - - bool - is_continuation () override - { - return is_continuation (std::integral_constant ::value>()); - } - - bool - is_continuation (std::true_type) - { - return Base::member.is_continuation(); - } - - bool - is_continuation (std::false_type) - { - return boost_asio_handler_cont_helpers:: - is_continuation (Base::member); - } -}; - -#ifdef _MSC_VER -#pragma warning (pop) -#endif - -template -struct is_shared_handler : public std::false_type -{ -}; - -//------------------------------------------------------------------------------ - -template -class handler_allocator -{ -private: - // We want a partial template specialization as a friend - // but that isn't allowed so we friend all versions. This - // should produce a compile error if Handler is not constructible - // from H. - // - template - friend class handler_allocator; - - Handler m_handler; - -public: - typedef T value_type; - typedef T* pointer; - - template - struct rebind - { - public: - typedef handler_allocator other; - }; - - handler_allocator() = delete; - - handler_allocator (Handler const& handler) - : m_handler (handler) - { - } - - template - handler_allocator ( - handler_allocator const& other) - : m_handler (other.m_handler) - { - } - - handler_allocator& - operator= (handler_allocator const&) = delete; - - pointer - allocate (std::ptrdiff_t n) - { - auto const size (n * sizeof (T)); - return static_cast ( - boost_asio_handler_alloc_helpers::allocate ( - size, m_handler)); - } - - void - deallocate (pointer p, std::ptrdiff_t n) - { - auto const size (n * sizeof (T)); - boost_asio_handler_alloc_helpers::deallocate ( - p, size, m_handler); - } - - // Work-around for MSVC not using allocator_traits - // in the implementation of shared_ptr - // -#ifdef _MSC_VER - void - destroy (T* t) - { - t->~T(); - } -#endif - - friend - bool - operator== (handler_allocator const& lhs, handler_allocator const& rhs) - { - return true; - } - - friend - bool - operator!= (handler_allocator const& lhs, handler_allocator const& rhs) - { - return ! (lhs == rhs); - } -}; - -} - -//------------------------------------------------------------------------------ - -/** Handler shared reference that provides io_service execution guarantees. */ -template -class shared_handler -{ -private: - template - friend class shared_handler_allocator; - - typedef shared_handler_wrapper_func < - Signature> wrapper_type; - - typedef std::shared_ptr ptr_type; - - ptr_type m_ptr; - -public: - shared_handler() - { - } - - template < - class DeducedHandler, - class = std::enable_if_t < - ! detail::is_shared_handler < - std::decay_t >::value && - std::is_constructible , - std::decay_t >::value - > - > - shared_handler (DeducedHandler&& handler) - { - typedef std::remove_reference_t Handler; - - #if BEAST_ASIO_NO_ALLOCATE_SHARED - m_ptr = std::make_shared > (std::forward (handler)); - #else - m_ptr = std::allocate_shared > (detail::handler_allocator ( - handler), std::forward (handler)); - #endif - } - - shared_handler (shared_handler&& other) - : m_ptr (std::move (other.m_ptr)) - { - } - - shared_handler (shared_handler const& other) - : m_ptr (other.m_ptr) - { - } - - shared_handler& - operator= (std::nullptr_t) - { - m_ptr = nullptr; - return *this; - } - - shared_handler& - operator= (shared_handler const& rhs) - { - m_ptr = rhs.m_ptr; - return *this; - } - - shared_handler& - operator= (shared_handler&& rhs) - { - m_ptr = std::move (rhs.m_ptr); - return *this; - } - - explicit - operator bool() const noexcept - { - return m_ptr.operator bool(); - } - - void - reset() - { - m_ptr.reset(); - } - - template -#if BEAST_ASIO_NO_HANDLER_RESULT_OF - void -#else - std::result_of_t (Args...)> -#endif - operator() (Args&&... args) const - { - return (*m_ptr)(std::forward (args)...); - } - - template - friend - void - asio_handler_invoke (Function&& f, shared_handler* h) - { - return h->m_ptr->invoke (f); - } - - friend - void* - asio_handler_allocate ( - std::size_t size, shared_handler* h) - { - return h->m_ptr->allocate (size); - } - - friend - void - asio_handler_deallocate ( - void* p, std::size_t size, shared_handler* h) - { - return h->m_ptr->deallocate (p, size); - } - - friend - bool - asio_handler_is_continuation ( - shared_handler* h) - { - return h->m_ptr->is_continuation (); - } -}; - -//------------------------------------------------------------------------------ - -namespace detail { - -template < - class Signature -> -struct is_shared_handler < - shared_handler -> : public std::true_type -{ -}; - -} - -//------------------------------------------------------------------------------ - -template -class shared_handler_allocator -{ -private: - template - friend class shared_handler_allocator; - - std::shared_ptr m_ptr; - -public: - typedef T value_type; - typedef T* pointer; - - shared_handler_allocator() = delete; - - template - shared_handler_allocator ( - shared_handler const& handler) - : m_ptr (handler.m_ptr) - { - } - - template - shared_handler_allocator ( - shared_handler_allocator const& other) - : m_ptr (other.m_ptr) - { - } - - pointer - allocate (std::ptrdiff_t n) - { - auto const size (n * sizeof (T)); - return static_cast ( - m_ptr->allocate (size)); - } - - void - deallocate (pointer p, std::ptrdiff_t n) - { - auto const size (n * sizeof (T)); - m_ptr->deallocate (p, size); - } - - friend - bool - operator== (shared_handler_allocator const& lhs, - shared_handler_allocator const& rhs) - { - return lhs.m_ptr == rhs.m_ptr; - } - - friend - bool - operator!= (shared_handler_allocator const& lhs, - shared_handler_allocator const& rhs) - { - return ! (lhs == rhs); - } -}; - -} -} - -#endif diff --git a/beast/asio/socket_wrapper.h b/beast/asio/socket_wrapper.h deleted file mode 100644 index 2b07c0b43e..0000000000 --- a/beast/asio/socket_wrapper.h +++ /dev/null @@ -1,826 +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_ASIO_SOCKET_WRAPPER_H_INCLUDED -#define BEAST_ASIO_SOCKET_WRAPPER_H_INCLUDED - -#include -#include - -#include - -namespace beast { -namespace asio { - -/** Wraps a reference to any object and exports all availble interfaces. - - If the object does not support an interface, calling those - member functions will behave as if a pure virtual was called. - - Note that only a reference to the underlying is stored. Management - of the lifetime of the object is controlled by the caller. - - Examples of the type of Object: - - asio::ip::tcp::socket - asio::ip::tcp::socket& - asio::ssl::stream - asio::ssl::stream - explain arg must be an io_context - explain socket_wrapper will create and take ownership of the tcp::socket - explain this_layer_type will be tcp::socket - explain next_layer () returns a asio::ip::tcp::socket& - explain lowest_layer () returns a asio::ip::tcp::socket& - - asio::ssl::stream > > - This makes my head explode -*/ -template -class socket_wrapper : public abstract_socket -{ -private: - Object m_object; - -public: - template - explicit socket_wrapper (Args&&... args) - : m_object (std::forward (args)...) - { - } - - socket_wrapper (socket_wrapper const&) = delete; - socket_wrapper& operator= (socket_wrapper const&) = delete; - - //-------------------------------------------------------------------------- - // - // socket_wrapper - // - //-------------------------------------------------------------------------- - - /** The type of the object being wrapped. */ - typedef typename boost::remove_reference ::type this_layer_type; - - /** Get a reference to this layer. */ - this_layer_type& this_layer () noexcept - { - return m_object; - } - - /** Get a const reference to this layer. */ - this_layer_type const& this_layer () const noexcept - { - return m_object; - } - - //-------------------------------------------------------------------------- - // - // abstract_socket - // - //-------------------------------------------------------------------------- - - void* this_layer_ptr (char const* type_name) const override - { - char const* const name (typeid (this_layer_type).name ()); - if (strcmp (name, type_name) == 0) - return const_cast (static_cast (&m_object)); - return nullptr; - } - -private: - BEAST_DEFINE_IS_CALL_POSSIBLE(has_get_io_service, get_io_service); - - BEAST_DEFINE_IS_CALL_POSSIBLE(has_lowest_layer, lowest_layer); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_cancel, cancel); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_shutdown, shutdown); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_close, close); - - BEAST_DEFINE_IS_CALL_POSSIBLE(has_accept, accept); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_async_accept, async_accept); - - BEAST_DEFINE_IS_CALL_POSSIBLE(has_read_some, read_some); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_write_some, write_some); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_async_read_some, async_read_some); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_async_write_some, async_write_some); - - BEAST_DEFINE_IS_CALL_POSSIBLE(has_set_verify_mode, set_verify_mode); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_handshake, handshake); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_async_handshake, async_handshake); - BEAST_DEFINE_IS_CALL_POSSIBLE(has_async_shutdown, async_shutdown); - - //-------------------------------------------------------------------------- - // - // Implementation - // - //-------------------------------------------------------------------------- - - template - struct Enabled : public std::integral_constant - { - }; - - //-------------------------------------------------------------------------- - // - // native_handle - // - //-------------------------------------------------------------------------- - -#if 0 - // This is a potential work-around for the problem with - // the has_type_native_handle_type template, but requires - // Boost 1.54 or later. - // - // This include will be needed: - // - // boost/tti/has_type.hpp - // - // - BOOST_TTI_HAS_TYPE(native_handle_type) - -#else - template - struct has_type_native_handle_type - { - typedef char yes; - typedef struct {char dummy[2];} no; - template static yes f(typename C::native_handle_type*); - template static no f(...); - #ifdef _MSC_VER - static bool const value = sizeof(f(0)) == 1; - #else - // This line fails to compile under Visual Studio 2012 - static bool const value = sizeof( - has_type_native_handle_type::f(0)) == 1; - #endif - }; - -#endif - - template ::value - > - struct extract_native_handle_type - { - typedef typename T::native_handle_type type; - }; - - template - struct extract_native_handle_type - { - typedef void type; - }; - - // This will be void if native_handle_type doesn't exist in Object - typedef typename extract_native_handle_type < - this_layer_type>::type native_handle_type; - - //-------------------------------------------------------------------------- - - bool native_handle (char const* type_name, void* dest) override - { - return native_handle (type_name, dest, - Enabled > ()); - } - - bool native_handle (char const* type_name, void* dest, - std::true_type) - { - char const* const name (typeid ( - typename this_layer_type::native_handle_type).name ()); - if (strcmp (name, type_name) == 0) - { - native_handle_type* const p (reinterpret_cast < - native_handle_type*> (dest)); - *p = m_object.native_handle (); - return true; - } - return false; - } - - bool native_handle (char const*, void*, - std::false_type) - { - pure_virtual_called(); - return false; - } - - //-------------------------------------------------------------------------- - // - // basic_io_object - // - //-------------------------------------------------------------------------- - - boost::asio::io_service& get_io_service () override - { - return get_io_service ( - Enabled > ()); - } - - boost::asio::io_service& get_io_service ( - std::true_type) - { - return m_object.get_io_service (); - } - - boost::asio::io_service& get_io_service ( - std::false_type) - { - pure_virtual_called(); - return *static_cast (nullptr); - } - - //-------------------------------------------------------------------------- - // - // basic_socket - // - //-------------------------------------------------------------------------- - - /* - To forward the lowest_layer_type type, we need to make sure it - exists in Object. This is a little more tricky than just figuring - out if Object has a particular member function. - - The problem is boost::asio::basic_socket_acceptor, which doesn't - have lowest_layer () or lowest_layer_type (). - */ - - template - struct has_type_lowest_layer_type - { - typedef char yes; - typedef struct {char dummy[2];} no; - template static yes f(typename C::lowest_layer_type*); - template static no f(...); -#ifdef _MSC_VER - static bool const value = sizeof(f(0)) == 1; -#else - // This line fails to compile under Visual Studio 2012 - static bool const value = sizeof(has_type_lowest_layer_type::f(0)) == 1; -#endif - }; - - template ::value > - struct extract_lowest_layer_type - { - typedef typename T::lowest_layer_type type; - }; - - template - struct extract_lowest_layer_type - { - typedef void type; - }; - - // This will be void if lowest_layer_type doesn't exist in Object - typedef typename extract_lowest_layer_type ::type lowest_layer_type; - - //-------------------------------------------------------------------------- - - void* lowest_layer_ptr (char const* type_name) const override - { - return lowest_layer_ptr (type_name, - Enabled > ()); - } - - void* lowest_layer_ptr (char const* type_name, - std::true_type) const - { - char const* const name (typeid (typename this_layer_type::lowest_layer_type).name ()); - if (strcmp (name, type_name) == 0) - return const_cast (static_cast (&m_object.lowest_layer ())); - return nullptr; - } - - void* lowest_layer_ptr (char const*, - std::false_type) const - { - pure_virtual_called(); - return nullptr; - } - - //-------------------------------------------------------------------------- - - error_code cancel (error_code& ec) override - { - return cancel (ec, - Enabled > ()); - } - - error_code cancel (error_code& ec, - std::true_type) - { - return m_object.cancel (ec); - } - - error_code cancel (error_code& ec, - std::false_type) - { - return pure_virtual_error (ec); - } - - //-------------------------------------------------------------------------- - - error_code shutdown (shutdown_type what, error_code& ec) override - { - return shutdown (what, ec, - Enabled > ()); - } - - - error_code shutdown (shutdown_type what, error_code& ec, - std::true_type) - { - return m_object.shutdown (what, ec); - } - - error_code shutdown (shutdown_type, error_code& ec, - std::false_type) - { - return pure_virtual_error (ec); - } - - //-------------------------------------------------------------------------- - - error_code close (error_code& ec) override - { - return close (ec, - Enabled > ()); - } - - error_code close (error_code& ec, - std::true_type) - { - return m_object.close (ec); - } - - error_code close (error_code& ec, - std::false_type) - { - return pure_virtual_error (ec); - } - - //-------------------------------------------------------------------------- - // - // basic_socket_acceptor - // - //-------------------------------------------------------------------------- - - // Extracts the underlying socket type from the protocol of another asio object - template - struct native_socket - { - typedef void* socket_type; - inline native_socket (abstract_socket&) - : m_socket (nullptr) - { - abstract_socket::pure_virtual_called(); - } - inline socket_type& get () - { - abstract_socket::pure_virtual_called(); - return m_socket; - } - inline socket_type& operator-> () - { - return get (); - } - private: - socket_type m_socket; - }; - - // Enabled if T::protocol_type::socket exists as a type - template - struct native_socket >::type> - { - typedef typename T::protocol_type::socket socket_type; - inline native_socket (abstract_socket& peer) - : m_socket_ptr (&peer.this_layer ()) - { - } - inline socket_type& get () noexcept - { - return *m_socket_ptr; - } - inline socket_type& operator-> () noexcept - { - return get (); - } - private: - socket_type* m_socket_ptr; - }; - - //-------------------------------------------------------------------------- - - error_code accept (abstract_socket& peer, error_code& ec) override - { - typedef typename native_socket ::socket_type socket_type; - return accept (peer, ec, - Enabled > ()); - } - - error_code accept (abstract_socket& peer, error_code& ec, - std::true_type) - { - return m_object.accept ( - native_socket (peer).get (), ec); - } - - error_code accept (abstract_socket&, error_code& ec, - std::false_type) - { - return pure_virtual_error (ec); - } - - //-------------------------------------------------------------------------- - - void async_accept (abstract_socket& peer, error_handler handler) override - { - typedef typename native_socket ::socket_type socket_type; - async_accept (peer, handler, - Enabled > ()); - } - - void async_accept (abstract_socket& peer, error_handler const& handler, - std::true_type) - { - m_object.async_accept ( - native_socket (peer).get (), handler); - } - - void async_accept (abstract_socket&, error_handler const& handler, - std::false_type) - { - get_io_service ().post (bind_handler ( - handler, pure_virtual_error())); - } - - //-------------------------------------------------------------------------- - // - // basic_stream_socket - // - //-------------------------------------------------------------------------- - - std::size_t - read_some (mutable_buffers buffers, error_code& ec) override - { - return read_some (buffers, ec, - Enabled > ()); - } - - std::size_t - read_some (mutable_buffers const& buffers, error_code& ec, - std::true_type) - { - return m_object.read_some (buffers, ec); - } - - std::size_t read_some (mutable_buffers const&, error_code& ec, - std::false_type) - { - ec = pure_virtual_error (); - return 0; - } - - //-------------------------------------------------------------------------- - - std::size_t - write_some (const_buffers buffers, error_code& ec) override - { - return write_some (buffers, ec, - Enabled > ()); - } - - std::size_t - write_some (const_buffers const& buffers, error_code& ec, - std::true_type) - { - return m_object.write_some (buffers, ec); - } - - std::size_t - write_some (const_buffers const&, error_code& ec, - std::false_type) - { - ec = pure_virtual_error (); - return 0; - } - - //-------------------------------------------------------------------------- - - void async_read_some (mutable_buffers buffers, - transfer_handler handler) override - { - async_read_some (buffers, handler, - Enabled > ()); - } - - void - async_read_some (mutable_buffers const& buffers, - transfer_handler const& handler, - std::true_type) - { - m_object.async_read_some (buffers, handler); - } - - void - async_read_some (mutable_buffers const&, - transfer_handler const& handler, - std::false_type) - { - get_io_service ().post (bind_handler ( - handler, pure_virtual_error(), 0)); - } - - //-------------------------------------------------------------------------- - - void - async_write_some (const_buffers buffers, - transfer_handler handler) override - { - async_write_some (buffers, handler, - Enabled > ()); - } - - void - async_write_some (const_buffers const& buffers, - transfer_handler const& handler, - std::true_type) - { - m_object.async_write_some (buffers, handler); - } - - void - async_write_some (const_buffers const&, - transfer_handler const& handler, - std::false_type) - { - get_io_service ().post (bind_handler ( - handler, pure_virtual_error(), 0)); - } - - //-------------------------------------------------------------------------- - // - // ssl::stream - // - //-------------------------------------------------------------------------- - - template - struct has_type_next_layer_type - { - typedef char yes; - typedef struct {char dummy[2];} no; - template static yes f(typename C::next_layer_type*); - template static no f(...); - #ifdef _MSC_VER - static bool const value = sizeof(f(0)) == 1; - #else - // This line fails to compile under Visual Studio 2012 - static bool const value = sizeof(has_type_next_layer_type::f(0)) == 1; - #endif - }; - - template ::value > - struct extract_next_layer_type - { - typedef typename T::next_layer_type type; - }; - - template - struct extract_next_layer_type - { - typedef void type; - }; - - // This will be void if next_layer_type doesn't exist in Object - typedef typename extract_next_layer_type ::type next_layer_type; - - //-------------------------------------------------------------------------- - - void* next_layer_ptr (char const* type_name) const override - { - return next_layer_ptr (type_name, - Enabled > ()); - } - - void* next_layer_ptr (char const* type_name, - std::true_type) const - { - char const* const name (typeid (typename this_layer_type::next_layer_type).name ()); - if (strcmp (name, type_name) == 0) - return const_cast (static_cast (&m_object.next_layer ())); - return nullptr; - } - - void* next_layer_ptr (char const*, - std::false_type) const - { - pure_virtual_called(); - return nullptr; - } - - //-------------------------------------------------------------------------- - - bool needs_handshake () override - { - return - has_handshake ::value || - has_async_handshake ::value; - } - - //-------------------------------------------------------------------------- - - void set_verify_mode (int verify_mode) override - { - set_verify_mode (verify_mode, - Enabled > ()); - - } - - void set_verify_mode (int verify_mode, - std::true_type) - { - m_object.set_verify_mode (verify_mode); - } - - void set_verify_mode (int, - std::false_type) - { - pure_virtual_called(); - } - - //-------------------------------------------------------------------------- - - error_code - handshake (handshake_type type, error_code& ec) override - { - return handshake (type, ec, - Enabled > ()); - } - - error_code - handshake (handshake_type type, error_code& ec, - std::true_type) - { - return m_object.handshake (type, ec); - } - - error_code - handshake (handshake_type, error_code& ec, - std::false_type) - { - return pure_virtual_error (ec); - } - - //-------------------------------------------------------------------------- - - void async_handshake (handshake_type type, error_handler handler) override - { - async_handshake (type, handler, - Enabled > ()); - } - - void async_handshake (handshake_type type, error_handler const& handler, - std::true_type) - { - m_object.async_handshake (type, handler); - } - - void async_handshake (handshake_type, error_handler const& handler, - std::false_type) - { - get_io_service ().post (bind_handler ( - handler, pure_virtual_error())); - } - - //-------------------------------------------------------------------------- - - error_code - handshake (handshake_type type, const_buffers buffers, - error_code& ec) override - { - return handshake (type, buffers, ec, - Enabled > ()); - } - - error_code - handshake (handshake_type type, const_buffers const& buffers, - error_code& ec, - std::true_type) - { - return m_object.handshake (type, buffers, ec); - } - - error_code - handshake (handshake_type, const_buffers const&, - error_code& ec, - std::false_type) - { - return pure_virtual_error (ec); - } - - //-------------------------------------------------------------------------- - - void async_handshake (handshake_type type, - const_buffers buffers, transfer_handler handler) override - { - async_handshake (type, buffers, handler, - Enabled > ()); - } - - void async_handshake (handshake_type type, const_buffers const& buffers, - transfer_handler const& handler, - std::true_type) - { - m_object.async_handshake (type, buffers, handler); - } - - void async_handshake (handshake_type, const_buffers const&, - transfer_handler const& handler, - std::false_type) - { - get_io_service ().post (bind_handler ( - handler, pure_virtual_error(), 0)); - } - - //-------------------------------------------------------------------------- - - error_code shutdown (error_code& ec) override - { - return shutdown (ec, - Enabled > ()); - } - - error_code shutdown (error_code& ec, - std::true_type) - { - return m_object.shutdown (ec); - } - - error_code shutdown (error_code& ec, - std::false_type) - { - return pure_virtual_error (ec); - } - - //-------------------------------------------------------------------------- - - void async_shutdown (error_handler handler) override - { - async_shutdown (handler, - Enabled > ()); - } - - void async_shutdown (error_handler const& handler, - std::true_type) - { - m_object.async_shutdown (handler); - } - - void async_shutdown (error_handler const& handler, - std::false_type) - { - get_io_service ().post (bind_handler ( - handler, pure_virtual_error())); - } -}; - -} -} - -#endif diff --git a/beast/asio/streambuf.h b/beast/asio/streambuf.h deleted file mode 100644 index 885b603a0f..0000000000 --- a/beast/asio/streambuf.h +++ /dev/null @@ -1,49 +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_ASIO_BASIC_STREAMBUF_H_INCLUDED -#define BEAST_ASIO_BASIC_STREAMBUF_H_INCLUDED - -#include -#include -#include - -namespace beast { -namespace asio { - -template > -class basic_streambuf : private Alloc -{ -private: - typedef std::allocator_traits alloc_traits; - std::vector bufs_; - -public: - ~basic_streambuf() - { - for (auto const& buf : bufs_) - alloc_traits::deallocate ( - boost::asio::buffer_cast(buf)); - } -} - -} // asio -} // beast - -#endif diff --git a/beast/asio/tests/enable_wait_for_async.test.cpp b/beast/asio/tests/enable_wait_for_async.test.cpp deleted file mode 100644 index fd529fed4f..0000000000 --- a/beast/asio/tests/enable_wait_for_async.test.cpp +++ /dev/null @@ -1,105 +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. -*/ -//============================================================================== - -#if BEAST_INCLUDE_BEASTCONFIG -#include -#endif - -#include - -#include -#include - -#include - -namespace beast { - -class enable_wait_for_async_test : public unit_test::suite -{ -public: - typedef boost::system::error_code error_code; - - void test() - { - struct handler - { - void operator()(error_code) - { - } - }; - - struct owner : asio::enable_wait_for_async - { - bool notified; - - owner() - : notified (false) - { - } - - void operator()() - { - { - boost::asio::io_service ios; - ios.post (asio::bind_handler (handler(), - error_code())); - ios.run(); - ios.reset(); - wait_for_async(); - } - - { - boost::asio::io_service ios; - ios.post (wrap_with_counter (asio::bind_handler ( - handler(), error_code()))); - ios.run(); - wait_for_async(); - } - - { - boost::asio::io_service ios; - handler h; - ios.post (wrap_with_counter (std::bind ( - &handler::operator(), &h, - error_code()))); - ios.run(); - wait_for_async(); - } - } - - void on_wait_for_async() - { - notified = true; - } - }; - - owner o; - o(); - expect (o.notified); - } - - void run() - { - test(); - } -}; - -BEAST_DEFINE_TESTSUITE(enable_wait_for_async,asio,beast); - -} diff --git a/beast/asio/tests/shared_handler.test.cpp b/beast/asio/tests/shared_handler.test.cpp deleted file mode 100644 index d32ef19614..0000000000 --- a/beast/asio/tests/shared_handler.test.cpp +++ /dev/null @@ -1,235 +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. -*/ -//============================================================================== - -#if BEAST_INCLUDE_BEASTCONFIG -#include -#endif - -#include - -#include - -// Disables is_constructible tests for std::function -// Visual Studio std::function fails the is_constructible tests -#ifndef BEAST_NO_STD_FUNCTION_CONSTRUCTIBLE -# ifdef _MSC_VER -# define BEAST_NO_STD_FUNCTION_CONSTRUCTIBLE 1 -# else -# define BEAST_NO_STD_FUNCTION_CONSTRUCTIBLE 0 -# endif -#endif - -namespace beast { - -class shared_handler_test : public unit_test::suite -{ -public: - struct test_results - { - bool call; - bool invoke; - bool alloc; - bool dealloc; - bool cont; - - test_results () - : call (false) - , invoke (false) - , alloc (false) - , dealloc (false) - , cont (false) - { - } - }; - - struct test_handler - { - std::reference_wrapper results; - - explicit test_handler (test_results& results_) - : results (results_) - { - } - - void operator() () - { - results.get().call = true; - } - - template - friend void asio_handler_invoke ( - Function& f, test_handler* h) - { - h->results.get().invoke = true; - f(); - } - - template - friend void asio_handler_invoke ( - Function const& f, test_handler* h) - { - h->results.get().invoke = true; - f(); - } - - friend void* asio_handler_allocate ( - std::size_t size, test_handler* h) - { - h->results.get().alloc = true; - return boost::asio::asio_handler_allocate (size); - } - - friend void asio_handler_deallocate ( - void* p, std::size_t size, test_handler* h) - { - h->results.get().dealloc = true; - boost::asio::asio_handler_deallocate (p, size); - } - - friend bool asio_handler_is_continuation ( - test_handler* h) - { - h->results.get().cont = true; - return true; - } - }; - - struct test_invokable - { - bool call; - - test_invokable () - : call (false) - { - } - - void operator() () - { - call = true; - } - }; - - template - bool async_op (Handler&& handler) - { - void* const p (boost_asio_handler_alloc_helpers::allocate (32, handler)); - handler(); - boost_asio_handler_alloc_helpers::deallocate (p, 32, handler); - return boost_asio_handler_cont_helpers::is_continuation (handler); - } - - void virtual_async_op (asio::shared_handler handler) - { - async_op (handler); - } - - void run() - { - #if ! BEAST_NO_STD_FUNCTION_CONSTRUCTIBLE - static_assert (! std::is_constructible < - std::function , int&&>::value, - "Cannot construct std::function from int&&"); - - static_assert (! std::is_constructible < - std::function , int>::value, - "Cannot construct std::function from int"); - - static_assert (! std::is_constructible < - asio::shared_handler , int>::value, - "Cannot construct shared_handler from int"); - #endif - - static_assert (std::is_constructible < - asio::shared_handler , - asio::shared_handler >::value, - "Should construct from "); - - static_assert (! std::is_constructible < - asio::shared_handler , - asio::shared_handler >::value, - "Can't construct from "); - - // Hooks called when using the raw handler - { - test_results r; - test_handler h (r); - - async_op (h); - expect (r.call); - expect (r.alloc); - expect (r.dealloc); - expect (r.cont); - - test_invokable f; - boost_asio_handler_invoke_helpers::invoke (std::ref (f), h); - expect (r.invoke); - expect (f.call); - } - - // Use of std::function shows the hooks not getting called - { - test_results r; - std::function fh ((test_handler) (r)); - - async_op (fh); - expect (r.call); - unexpected (r.alloc); - unexpected (r.dealloc); - unexpected (r.cont); - - test_invokable f; - boost_asio_handler_invoke_helpers::invoke (std::ref (f), fh); - unexpected (r.invoke); - expect (f.call); - } - - // Make sure shared_handler calls the hooks - { - test_results r; - asio::shared_handler sh ((test_handler)(r)); - - async_op (sh); - expect (r.call); - expect (r.alloc); - expect (r.dealloc); - expect (r.cont); - - test_invokable f; - boost_asio_handler_invoke_helpers::invoke (std::ref (f), sh); - expect (r.invoke); - expect (f.call); - } - - // Make sure shared_handler via implicit conversion calls hooks - { - test_results r; - test_handler h (r); - - virtual_async_op ((test_handler) (r)); - expect (r.call); - expect (r.alloc); - expect (r.dealloc); - expect (r.cont); - } - } -}; - -BEAST_DEFINE_TESTSUITE(shared_handler,asio,beast); - -} diff --git a/beast/asio/tests/wrap_handler.test.cpp b/beast/asio/tests/wrap_handler.test.cpp deleted file mode 100644 index 8c3fe0a8b2..0000000000 --- a/beast/asio/tests/wrap_handler.test.cpp +++ /dev/null @@ -1,280 +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. -*/ -//============================================================================== - -#if BEAST_INCLUDE_BEASTCONFIG -#include -#endif - -#include - -#include - -#include - -#include -#include -#include - -namespace beast { -namespace asio { - -//------------------------------------------------------------------------------ - -// Displays the order of destruction of parameters in the bind wrapper -// -class boost_bind_test : public unit_test::suite -{ -public: - struct Result - { - std::string text; - - void push_back (std::string const& s) - { - if (! text.empty()) - text += ", "; - text += s; - } - }; - - struct Payload - { - std::reference_wrapper m_result; - std::string m_name; - - explicit Payload (Result& result, std::string const& name) - : m_result (result) - , m_name (name) - { - } - - ~Payload () - { - m_result.get().push_back (m_name); - } - }; - - struct Arg - { - std::shared_ptr m_payload; - - Arg (Result& result, std::string const& name) - : m_payload (std::make_shared (result, name)) - { - } - }; - - static void foo (Arg const&, Arg const&, Arg const&) - { - } - - void run() - { - { - Result r; - { - boost::bind (&foo, - Arg (r, "one"), - Arg (r, "two"), - Arg (r, "three")); - } - log << - std::string ("boost::bind (") + r.text + ")"; - } - - { - Result r; - { - std::bind (&foo, - Arg (r, "one"), - Arg (r, "two"), - Arg (r, "three")); - } - - log << - std::string ("std::bind (") + r.text + ")"; - } - - pass(); - } -}; - -BEAST_DEFINE_TESTSUITE(boost_bind,asio,beast); - -//------------------------------------------------------------------------------ - -class wrap_handler_test : public unit_test::suite -{ -public: - struct test_results - { - bool call; - bool invoke; - bool alloc; - bool dealloc; - bool cont; - - test_results () - : call (false) - , invoke (false) - , alloc (false) - , dealloc (false) - , cont (false) - { - } - }; - - struct test_handler - { - std::reference_wrapper results; - - explicit test_handler (test_results& results_) - : results (results_) - { - } - - void operator() () - { - results.get().call = true; - } - - template - friend void asio_handler_invoke ( - Function& f, test_handler* h) - { - h->results.get().invoke = true; - f(); - } - - template - friend void asio_handler_invoke ( - Function const& f, test_handler* h) - { - h->results.get().invoke = true; - f(); - } - - friend void* asio_handler_allocate ( - std::size_t, test_handler* h) - { - h->results.get().alloc = true; - return nullptr; - } - - friend void asio_handler_deallocate ( - void*, std::size_t, test_handler* h) - { - h->results.get().dealloc = true; - } - - friend bool asio_handler_is_continuation ( - test_handler* h) - { - h->results.get().cont = true; - return true; - } - }; - - struct test_invokable - { - bool call; - - test_invokable () - : call (false) - { - } - - void operator() () - { - call = true; - } - }; - - template - bool async_op (Handler&& handler) - { - void* const p (boost_asio_handler_alloc_helpers::allocate (32, handler)); - (handler)(); - boost_asio_handler_alloc_helpers::deallocate (p, 32, handler); - return boost_asio_handler_cont_helpers::is_continuation (handler); - } - - void run() - { - // Hooks called when using the raw handler - { - test_results r; - test_handler h (r); - - async_op (h); - expect (r.call); - expect (r.alloc); - expect (r.dealloc); - expect (r.cont); - - test_invokable f; - boost_asio_handler_invoke_helpers::invoke (std::ref (f), h); - expect (r.invoke); - expect (f.call); - } - - // Use of boost::bind shows the hooks not getting called - { - test_results r; - test_handler h (r); - auto b (std::bind (&test_handler::operator(), &h)); - - async_op (b); - expect (r.call); - unexpected (r.alloc); - unexpected (r.dealloc); - unexpected (r.cont); - - test_invokable f; - boost_asio_handler_invoke_helpers::invoke (std::ref (f), b); - unexpected (r.invoke); - expect (f.call); - } - - // Make sure the wrapped handler calls the hooks - { - test_results r; - test_handler h (r); - auto w (wrap_handler ( - std::bind (&test_handler::operator(), test_handler(r)), h)); - - async_op (w); - expect (r.call); - expect (r.alloc); - expect (r.dealloc); - expect (r.cont); - - test_invokable f; - boost_asio_handler_invoke_helpers::invoke (std::ref (f), w); - expect (r.invoke); - expect (f.call); - } - } -}; - -BEAST_DEFINE_TESTSUITE(wrap_handler,asio,beast); - -} -} - diff --git a/beast/asio/wrap_handler.h b/beast/asio/wrap_handler.h deleted file mode 100644 index 4bda7f4b9a..0000000000 --- a/beast/asio/wrap_handler.h +++ /dev/null @@ -1,176 +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_ASIO_WRAP_HANDLER_H_INCLUDED -#define BEAST_ASIO_WRAP_HANDLER_H_INCLUDED - -#include -#include -#include - -#include // -#include - -namespace beast { -namespace asio { - -#ifdef _MSC_VER -#pragma warning (push) -#pragma warning (disable: 4512) // assignment operator could not be generated -#endif - -namespace detail { - -/** A handler which wraps another handler using a specfic context. - The handler is invoked with the same io_service execution guarantees - as the provided context. - @note A copy of Context is made. -*/ -template -class wrapped_handler -{ -private: - Handler m_handler; - Context m_context; - bool m_continuation; - - // If this goes off, consider carefully what the intent is. - static_assert (! std::is_reference ::value, - "Handler should not be a reference type"); - -public: - wrapped_handler (bool continuation, Handler&& handler, Context context) - : m_handler (std::move (handler)) - , m_context (context) - , m_continuation (continuation ? true : - boost_asio_handler_cont_helpers::is_continuation (context)) - { - } - - wrapped_handler (bool continuation, Handler const& handler, Context context) - : m_handler (handler) - , m_context (context) - , m_continuation (continuation ? true : - boost_asio_handler_cont_helpers::is_continuation (context)) - { - } - - template - void - operator() (Args&&... args) - { - m_handler (std::forward (args)...); - } - - template - void - operator() (Args&&... args) const - { - m_handler (std::forward (args)...); - } - - template - friend - void - asio_handler_invoke (Function& f, wrapped_handler* h) - { - boost_asio_handler_invoke_helpers:: - invoke (f, h->m_context); - } - - template - friend - void - asio_handler_invoke (Function const& f, wrapped_handler* h) - { - boost_asio_handler_invoke_helpers:: - invoke (f, h->m_context); - } - - friend - void* - asio_handler_allocate (std::size_t size, wrapped_handler* h) - { - return boost_asio_handler_alloc_helpers:: - allocate (size, h->m_context); - } - - friend - void - asio_handler_deallocate (void* p, std::size_t size, wrapped_handler* h) - { - boost_asio_handler_alloc_helpers:: - deallocate (p, size, h->m_context); - } - - friend - bool - asio_handler_is_continuation (wrapped_handler* h) - { - return h->m_continuation; - } -}; - -} - -//------------------------------------------------------------------------------ - -// Tag for dispatching wrap_handler with is_continuation == true -enum continuation_t -{ - continuation -}; - -/** Returns a wrapped handler so it executes within another context. - The handler is invoked with the same io_service execution guarantees - as the provided context. The handler will be copied if necessary. - @note A copy of Context is made. -*/ -/** @{ */ -template -detail::wrapped_handler < - std::remove_reference_t , - Context -> -wrap_handler (DeducedHandler&& handler, Context const& context, - bool continuation = false) -{ - typedef std::remove_reference_t Handler; - return detail::wrapped_handler (continuation, - std::forward (handler), context); -} - -template -detail::wrapped_handler < - std::remove_reference_t , - Context -> -wrap_handler (continuation_t, DeducedHandler&& handler, - Context const& context) -{ - typedef std::remove_reference_t Handler; - return detail::wrapped_handler (true, - std::forward (handler), context); -} -/** @} */ - -} -} - -#endif diff --git a/beast/http/HTTP.unity.cpp b/beast/http/HTTP.unity.cpp index 405b219bab..750ba7fcdd 100644 --- a/beast/http/HTTP.unity.cpp +++ b/beast/http/HTTP.unity.cpp @@ -22,14 +22,11 @@ #endif #include -#include #include #include #include #include -#include -#include #include #include #include diff --git a/beast/http/basic_url.h b/beast/http/basic_url.h deleted file mode 100644 index f5593feedd..0000000000 --- a/beast/http/basic_url.h +++ /dev/null @@ -1,174 +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_HTTP_BASIC_URL_H_INCLUDED -#define BEAST_HTTP_BASIC_URL_H_INCLUDED - -#include -#include - -#include -#include -#include -#include -#include - -namespace beast { -namespace http { - -namespace detail { - -class basic_url_base -{ -public: - typedef char value_type; - typedef std::char_traits traits_type; - - typedef boost::basic_string_ref < - value_type, traits_type> string_ref; - - string_ref - scheme () const noexcept - { - return m_scheme; - } - - string_ref - host () const noexcept - { - return m_host; - } - - std::uint16_t - port () const noexcept - { - return m_port; - } - - string_ref - port_string () const noexcept - { - return m_port_string; - } - - string_ref - path () const noexcept - { - return m_path; - } - - string_ref - query () const noexcept - { - return m_query; - } - - string_ref - fragment () const noexcept - { - return m_fragment; - } - - string_ref - userinfo () const noexcept - { - return m_userinfo; - } - -protected: - void - parse_impl (string_ref s, boost::system::error_code& ec); - - string_ref m_string_ref; - string_ref m_scheme; - string_ref m_host; - std::uint16_t m_port; - string_ref m_port_string; - string_ref m_path; - string_ref m_query; - string_ref m_fragment; - string_ref m_userinfo; -}; - -} - -/** A URL. */ -template < - class Alloc = std::allocator -> -class basic_url : public detail::basic_url_base -{ -public: - typedef std::basic_string < - value_type, traits_type, Alloc> string_type; - - basic_url() = default; - - explicit basic_url (Alloc const& alloc) - : m_string (alloc) - { - } - - void - parse (string_ref s) - { - boost::system::error_code ec; - parse (s, ec); - if (ec) - throw std::invalid_argument ("invalid url string"); - } - - boost::system::error_code - parse (string_ref s, - boost::system::error_code& ec) - { - parse_impl (s, ec); - if (!ec) - { - m_string = string_type (s.begin(), s.end()); - m_string_ref = m_string; - } - return ec; - } - - bool - empty () const noexcept - { - return m_string.empty(); - } - - template - friend - int - compare (basic_url const& lhs, - basic_url const& rhs) noexcept - { - return lhs.m_buf.compare (rhs.m_buf); - } - -private: - string_type m_string; -}; - -using url = basic_url >; - -} -} - -#endif diff --git a/beast/http/client_session.h b/beast/http/client_session.h deleted file mode 100644 index 633ea03afa..0000000000 --- a/beast/http/client_session.h +++ /dev/null @@ -1,727 +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_ASIO_HTTP_BASIC_SESSION_H_INCLUDED -#define BEAST_ASIO_HTTP_BASIC_SESSION_H_INCLUDED - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include - -#include // -#include // - -#include // REMOVE ASAP! - -namespace beast { -namespace http { - -template -boost::asio::basic_streambuf & -operator<< (boost::asio::basic_streambuf & stream, T const& t) -{ - std::stringstream ss; - ss << t; - std::string const s (ss.str()); - auto const b (boost::asio::buffer (s)); - auto const len (boost::asio::buffer_size (b)); - boost::asio::buffer_copy (stream.prepare (len), b); - stream.commit (len); - return stream; -} - -template -boost::asio::basic_streambuf & -operator<< (boost::asio::basic_streambuf & stream, - std::string const& s) -{ - auto const b (boost::asio::buffer (s)); - auto const len (boost::asio::buffer_size (b)); - boost::asio::buffer_copy (stream.prepare (len), b); - stream.commit (len); - return stream; -} - -#ifdef _MSC_VER -#pragma warning (push) -#pragma warning (disable: 4100) // unreferenced formal parameter -#endif - -/** Provides asynchronous HTTP client service on a socket. */ -template -class client_session - : public asio::enable_wait_for_async > - , private raw_parser::callback -{ -private: - BOOST_TRIBOOL_THIRD_STATE(unspecified); - - BEAST_DEFINE_IS_CALL_POSSIBLE(has_keep_alive, keep_alive); - - template - struct Enabled : public std::integral_constant - { - }; - - static_assert (! std::is_const ::value, - "Socket cannot be const"); - - typedef boost::system::error_code error_code; - typedef boost::asio::streambuf write_buffers; - typedef boost::basic_string_ref < - char, ci_char_traits> ci_string_ref; - - class abstract_request; - class abstract_response; - - Socket m_socket; - boost::asio::io_service::strand m_strand; - boost::asio::deadline_timer m_timer; - - asio::shared_handler m_handler; - std::unique_ptr m_request; - std::unique_ptr m_response; - - raw_parser m_parser; - write_buffers m_write_buffer; - boost::asio::mutable_buffer m_read_buffer; - std::string m_field; - std::string m_value; - - bool m_complete : 1; - bool m_keep_alive : 1; - -public: - typedef Socket stream_type; - - client_session& operator= (client_session const&) = delete; - - template - explicit client_session (Args&&... args) - : m_socket (std::forward (args)...) - , m_strand (m_socket.get_io_service()) - , m_timer (m_socket.get_io_service()) - , m_parser (*this) - { - } - - ~client_session() = default; - - /** Returns the stream associated with the session. */ - /** @{ */ - stream_type& - stream() - { - return m_socket; - } - - stream_type const& - stream() const - { - return m_socket; - } - /** @} */ - - void - cancel() - { - error_code ec; - m_socket.cancel(ec); - } - - /** Fetch a resource asynchronously. */ - template < - class Request, - class Response, - class Handler - > - void - async_get (Request request, Response response, Handler&& handler) - { - m_handler = std::forward (handler); - - m_request = std::make_unique < - wrapped_request > (request); - - m_response = std::make_unique < - wrapped_response > (response); - - start(); - } - - template < - class Handler - > - void - async_get (std::string const&) noexcept - { - } - -private: - class abstract_request - { - public: - virtual - ~abstract_request() - { - } - - virtual - boost::tribool - keep_alive () = 0; - - virtual - void - headers (write_buffers& buffer) = 0; - }; - - template - class wrapped_request : public abstract_request - { - private: - typedef std::remove_reference_t request_type; - - Request m_request; - - public: - explicit wrapped_request (Request request) - : m_request (request) - { - } - - wrapped_request (wrapped_request const&) = delete; - - private: - boost::tribool - keep_alive() override - { - return keep_alive (Enabled >()); - } - - boost::tribool - keep_alive (std::true_type) - { - return m_request.keep_alive(); - } - - boost::tribool - keep_alive (std::false_type) - { - return unspecified; - } - - class submit - { - private: - write_buffers& m_buffer; - - public: - explicit submit (write_buffers& buffer) - : m_buffer (buffer) - { - } - - // Throws if an invalid request field is specified. - // Invalid fields are ones that the client_session inserts - // itself, such as keep-alive. - // - static void check_request_field (std::string const& field) - { - static std::vector reserved = - { - "Content-Length", - "Connection" - }; - - if (std::any_of (reserved.cbegin(), reserved.cend(), - [&](typename decltype(reserved)::value_type const& s) - { - return detail::field_eq (field, s); - })) - throw std::invalid_argument ( - "Reserved HTTP header in request"); - } - - template - void - operator() (F const& f, V const& v) - { - check_request_field (f); - - auto const fb (boost::asio::buffer (f)); - m_buffer.commit (boost::asio::buffer_copy ( - m_buffer.prepare (boost::asio::buffer_size (fb)), fb)); - m_buffer << ": "; - auto const vb (boost::asio::buffer (v)); - m_buffer.commit (boost::asio::buffer_copy ( - m_buffer.prepare (boost::asio::buffer_size (vb)), vb)); - m_buffer << "\r\n"; - } - }; - - void - headers (write_buffers& buffer) override - { - submit f (buffer); - m_request.template headers < - std::add_lvalue_reference_t > (f); - } - }; - - class abstract_response - { - public: - abstract_response() = default; - abstract_response (abstract_response const&) = default; - abstract_response& operator= (abstract_response const&) = default; - - virtual - ~abstract_response() = default; - - virtual - boost::asio::mutable_buffer - buffer () = 0; - - virtual - error_code - header (std::string const& field, - std::string const& value) = 0; - - virtual - error_code - body (boost::asio::const_buffer in) = 0; - - }; - - template - class wrapped_response : public abstract_response - { - private: - Response m_response; - - public: - explicit wrapped_response (Response response) - : m_response (response) - { - } - - wrapped_response (wrapped_response const&) = delete; - - boost::asio::mutable_buffer - buffer() override - { - return m_response.buffer(); - } - - error_code - header (std::string const& field, - std::string const& value) override - { - return m_response.header (field, value); - } - - virtual - error_code - body (boost::asio::const_buffer in) - { - return m_response.body (in); - } - }; - - void upcall (error_code const& ec, bool continuation = true) - { - if (m_handler) - { - // TODO cancel all pending i/o here? - - if (continuation) - { - m_handler (ec); - m_handler = nullptr; - } - else - { - m_socket.get_io_service().post ( - asio::bind_handler ( - std::move (m_handler), ec)); - assert (! m_handler); - } - } - } - - void start() - { - // reset and setup state - - m_parser.reset (raw_parser::response); - - m_write_buffer.consume (m_write_buffer.size()); - m_write_buffer << - "GET / HTTP/1.0\r\n"; - m_request->headers (m_write_buffer); - m_write_buffer << - "Content-Length: 0\r\n" - "\r\n"; - - m_read_buffer = m_response->buffer(); - - m_field = std::string(); - m_value = std::string(); - - m_complete = false; - m_keep_alive = false; - - async_write_some (false); - } - - // - // request - // - - bool - async_write_some (bool continuation = true) - { - auto const& data (m_write_buffer.data()); - auto const size (boost::asio::buffer_size ( - m_write_buffer.data())); - - if (size > 0) - { - m_socket.async_write_some (data, this->wrap_with_counter ( - m_strand.wrap (asio::wrap_handler (std::bind ( - &client_session::handle_write, this, - asio::placeholders::error, - asio::placeholders::bytes_transferred), - continuation)))); - return true; - } - return false; - } - - void - handle_write (error_code ec, std::size_t bytes_transferred) - { - if (ec) - return upcall (ec); - - m_write_buffer.consume (bytes_transferred); - - if (async_write_some()) - return; - - // write finished - - //if (! keep_alive) - { - m_socket.shutdown ( - boost::asio::socket_base::shutdown_send, ec); - // VFALCO What do we do with ec? - } - - // now read - - async_read_some (true); - } - - // - // response - // - - void - async_read_some (bool continuation = true) - { - m_socket.async_read_some (boost::asio::mutable_buffers_1 ( - m_read_buffer), this->wrap_with_counter ( - m_strand.wrap (asio::wrap_handler (std::bind ( - &client_session::handle_read, this, - asio::placeholders::error, - asio::placeholders::bytes_transferred), - continuation)))); - }; - - void - handle_read (error_code ec, std::size_t bytes_transferred) - { - if (ec != boost::asio::error::eof) - { - if (ec) - return upcall (ec); - - std::size_t bytes_consumed; - std::tie (ec, bytes_consumed) = m_parser.process_data ( - boost::asio::buffer_cast (m_read_buffer), - bytes_transferred); - - // TODO Handle leftover bytes - //assert (ec || bytes_consumed == bytes_transferred); - - if (ec) - return upcall (ec); - - if (! m_complete) - return async_read_some(); - } - else - { - // This is here for when we expect keep-alive but - // the server ends up closing the connection erroneously. - if (m_keep_alive) - { - m_keep_alive = false; - // warning: Got EOF on keep-alive - } - - ec = m_parser.process_eof(); - } - - if (! m_complete) - { - // custom error - ec = error_code (boost::system::errc::no_message_available, - boost::system::generic_category()); - } - - if (ec) - return upcall (ec); - - // We have a complete response - - if (! m_keep_alive) - { - // VFALCO NOTE This is surely wrong for ssl::stream - { - error_code ec_; - m_socket.shutdown ( - boost::asio::socket_base::shutdown_receive, ec_); - } - - { - error_code ec_; - m_socket.close (ec_); - assert (! ec_); - } - } - - m_request.reset(); - m_response.reset(); - m_handler (ec); - - // done - } - - // - // parser - // - - error_code - do_header() - { - error_code ec; - - if (! m_value.empty()) - { - ec = m_response->header (m_field, m_value); - - m_field.clear(); - m_value.clear(); - } - - return ec; - } - - error_code - on_response () override - { - m_field = decltype(m_field)(); - m_value = decltype(m_value)(); - return error_code(); - } - - error_code - on_url ( - void const* in, std::size_t bytes) override - { - // Shouldn't be called for HTTP responses - assert (false); - return error_code(); - } - - error_code - on_status (int status_code, - void const* in, std::size_t bytes) override - { - return error_code(); - } - - error_code - on_header_field ( - void const* in, std::size_t bytes) override - { - do_header(); - m_field.append (static_cast (in), bytes); - return error_code(); - } - - error_code - on_header_value ( - void const* in, std::size_t bytes) override - { - m_value.append (static_cast (in), bytes); - return error_code(); - } - - error_code - on_headers_done ( - bool keep_alive) override - { - do_header(); - - return error_code(); - } - - error_code - on_body (bool, - void const* in, std::size_t bytes) override - { - m_response->body ( - boost::asio::const_buffer (in, bytes)); - return error_code(); - } - - error_code - on_message_complete (bool keep_alive) override - { - m_keep_alive = keep_alive; - m_complete = true; - return error_code(); - } -}; - -#ifdef _MSC_VER -#pragma warning (pop) -#endif - -//------------------------------------------------------------------------------ - -/** Synchronous HTTP client session. */ -template -class sync_client_session -{ -private: - typedef boost::system::error_code error_code; - - boost::asio::io_service m_ios; - Socket m_socket; - error_code m_ec; - - static_assert (std::is_same >::value, - "Socket cannot be a reference or const type"); - - struct sync_handler - { - std::reference_wrapper m_session; - - sync_handler (sync_client_session& session) - : m_session (session) - { - } - - void operator() (boost::system::error_code ec) - { - m_session.get().m_ec = ec; - } - }; - -public: - typedef std::remove_reference_t next_layer_type; - typedef typename next_layer_type::lowest_layer_type lowest_layer_type; - - sync_client_session() - : m_socket (m_ios) - { - } - - sync_client_session (sync_client_session const&) = delete; - - // VFALCO We might be able to get away with having move ctor/assign - - ~sync_client_session() = default; - - next_layer_type& - next_layer() noexcept - { - return m_socket; - } - - next_layer_type const& - next_layer() const noexcept - { - } - - lowest_layer_type& - lowest_layer() noexcept - { - return m_socket.lowest_layer(); - } - - lowest_layer_type const& - lowest_layer() const noexcept - { - return m_socket.lowest_layer(); - } - - template - error_code - get (Request& request, Response& response) - { - client_session session (m_socket); - session.template async_get < - std::add_lvalue_reference_t , - std::add_lvalue_reference_t , - sync_handler> ( - request, response, sync_handler (*this)); - m_ios.run(); - m_ios.reset(); - return m_ec; - } -}; - -} -} - -#endif diff --git a/beast/http/tests/basic_url.test.cpp b/beast/http/tests/basic_url.test.cpp deleted file mode 100644 index d077663bec..0000000000 --- a/beast/http/tests/basic_url.test.cpp +++ /dev/null @@ -1,56 +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. -*/ -//============================================================================== - -#include - -#include - -namespace beast { - -class basic_url_test : public unit_test::suite -{ -public: - void - run () - { - std::vector const urls { - "http://www.example.com/#%c2%a9", - "http://127.0.0.1:443", - "http://192.168.0.1 hello.urltest.lookout.net/", - "http://\\uff10\\uff38\\uff43\\uff10\\uff0e\\uff10\\uff12\\uff15\\uff10\\uff0e\\uff10\\uff11.urltest.lookout.net/" - }; - http::url url; - for (auto const& s : urls) - { - try - { - url.parse (s); - pass(); - } - catch(...) - { - fail(); - } - } - } -}; - -BEAST_DEFINE_TESTSUITE_MANUAL(basic_url,http,beast); - -} diff --git a/beast/http/tests/client_session.test.cpp b/beast/http/tests/client_session.test.cpp deleted file mode 100644 index 85bab859c6..0000000000 --- a/beast/http/tests/client_session.test.cpp +++ /dev/null @@ -1,376 +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. -*/ -//============================================================================== - -// LIBS: pthread -// MODULES: urls_large_data.cpp ../impl/raw_parser.cpp ../impl/joyent_parser.cpp - -#if BEAST_INCLUDE_BEASTCONFIG -#include "../../BeastConfig.h" -#endif - -#include - -#include -#include -#include -#include -#include - -#include - -#include -#include - -namespace beast { -namespace http { - -/** Allows thread-safe forward traversal of a sequence. - - Each time the shared_iterator is dereferenced it provides an element in - the sequence or the one-past-the-end iterator if there are no elements - remaining in the sequence. Access to the shared iterator is thread safe: - multiple threads of execution can request iterators from the sequence, - and no two threads will see the same iterator. - - Any operations on the underlying container which would invalidate - iterators or change the sequence of elements pointed to by the range - of iterators referenced by the shared_iterator, results in undefined - behavior. -*/ -template -class shared_iterator -{ -public: - static_assert (std::is_same >::value, - "Iterator may not be a reference or const type"); - - typedef Iterator value_type; - -private: - std::mutex m_mutex; - Iterator m_iter; - Iterator m_end; - -public: - /** Construct the iteration from the range [first, last) */ - shared_iterator (Iterator first, Iterator last) - : m_iter (first) - , m_end (last) - { - } - - /** Obtains the next iterator in the sequence. - Post-condition - Current shared position in the sequence is advanced by one. - Thread safety: - Can be called from any thread at any time. - */ - Iterator - operator* () - { - std::lock_guard lock (m_mutex); - if (m_iter == m_end) - return m_iter; - return m_iter++; - } - - /** Returns the one-past-the end iterator for the sequence. - Thread safety: - Can be called from any thread at any time. - */ - Iterator - end() const - { - return m_end; - } -}; - -//------------------------------------------------------------------------------ - -class client_session_test : public unit_test::suite -{ -public: - typedef boost::system::error_code error_code; - - //-------------------------------------------------------------------------- - - /** Used to submit HTTP requests. */ - class Request - { - private: - typedef std::string value_type; - typedef std::string string_type; - - std::unordered_map m_headers; - - // This also works, for allowing header values to - // span multiple discontiguous memory buffers. - // - std::unordered_map > m_headers_plus; - - class vector_proxy - { - private: - std::reference_wrapper > m_vec; - - public: - explicit vector_proxy (std::vector & vec) - : m_vec (vec) - { - } - - vector_proxy& operator= (string_type const& s) - { - m_vec.get().emplace_back (s); - return *this; - } - }; - - public: - bool keep_alive() - { - return false; - } - - // Use this to set the fields - std::string& - operator[] (std::string const& field) - { - return m_headers[field]; - } - - /** Calls Function for each header. - - Requirements: - - `X` The type `Function` - `Y` A type meeting this requirement: - ConvertibleToConstBuffer - `Z` A type meeting either requirement: - ConstBufferSequence - ConvertibleToConstBuffer - `f` A value of type `X` - `n` A value of type `Y` - `v` A value of type `Z` - - The expression - - f (n, v); - - must be well formed. - */ - template - void - headers (Function f) - { - for (auto const& h : m_headers) - f (h.first, h.second); - } - }; - - //-------------------------------------------------------------------------- - - class Response - { - private: - typedef boost::system::error_code error_code; - asio::memory_buffer m_buffer; - boost::asio::streambuf m_body; - - public: - enum - { - buffer_bytes = 4192 - }; - - typedef std::vector > headers_type; - - headers_type headers; - - Response() - : m_buffer (buffer_bytes) - { - } - - boost::asio::mutable_buffer - buffer() - { - return boost::asio::mutable_buffer ( - m_buffer.data(), m_buffer.size()); - } - - template - error_code - header (FieldString const& field, ValueString const& value) - { - headers.push_back (std::make_pair (field, value)); - return error_code(); - } - - error_code - body (boost::asio::const_buffer in) - { - m_body.commit (boost::asio::buffer_copy ( - m_body.prepare (boost::asio::buffer_size (in)), - boost::asio::buffer (in))); - return error_code(); - } - - std::size_t - size() const - { - return m_body.size(); - } - - std::string - data() const - { - std::string s; - s.resize (m_body.size()); - boost::asio::buffer_copy (boost::asio::buffer ( - &s[0], s.size()), m_body.data()); - return s; - } - }; - - //-------------------------------------------------------------------------- - - template - error_code - visit (Session& session, std::string const& url) - { - error_code ec; - typedef boost::asio::ip::tcp::resolver resolver_t; - boost::asio::io_service ios; - resolver_t r (ios); - auto iter (r.resolve (resolver_t::query ( - url, "80", resolver_t::query::numeric_service), ec)); - - if (ec) - return ec; - - if (iter != resolver_t::iterator()) - { - session.next_layer().connect (iter->endpoint(), ec); - if (ec) - return ec; - - Request req; - req ["User-Agent"] = "rippled-http-client/1.0"; - req ["Host"] = url + ":80"; - req ["Content-Type"] = "application/text"; - req ["Accept"] = "application/text"; - - //req ["Content-length"] = "0"; - //req.prepare ("GET / HTTP/1.0"); - - Response resp; - ec = session.get (req, resp); - - if (ec) - { - // hack - session.next_layer().close(); - } - - log << - "GET " << url << " " << ec.message(); - - for (auto const& h : resp.headers) - log << h.first << ": " << h.second; - - log << resp.data(); - log << " "; - } - - return ec; - } - - //-------------------------------------------------------------------------- - - template - void - concurrent_get (shared_iterator & iter) - { - typedef boost::asio::ip::tcp::socket socket_type; - for (auto cur (*iter); cur != iter.end(); cur = *iter) - { - sync_client_session session; - std::string const base (*cur); - std::string url; - url = "www." + base; - visit (session, url); - } - } - - // Perform HTTP get on a sequence of URLs in parallel - // Requirements - // Sequence must me - // Sequence::value_type must be convertible to std::string - template - void test_concurrent_get (Iterator first, Iterator last) - { -#if 0 -last = first; -std::advance (last, 3000); -#endif - - shared_iterator iter (first, last); - - std::vector pool; -#if 0 - std::size_t const hardware_concurrency ( - std::max (std::thread::hardware_concurrency(), - 2u - )); -#else - std::size_t const hardware_concurrency (1); -#endif - - for (std::size_t n (hardware_concurrency); n--;) - pool.emplace_back (std::bind ( - &client_session_test::concurrent_get , this, - std::ref (iter))); - - for (auto& t : pool) - t.join(); - - pass(); - } - - template - void test_concurrent_get (Sequence const& sequence) - { - auto last (std::begin(sequence)); - std::advance (last, std::min (std::size_t(1), sequence.size())); - test_concurrent_get (std::begin (sequence), last); - } - - void run() - { - test_concurrent_get (urls_large_data()); - } -}; - -BEAST_DEFINE_TESTSUITE_MANUAL(client_session,http,beast); - -} -} diff --git a/beast/module/asio/async/AsyncObject.h b/beast/module/asio/AsyncObject.h similarity index 96% rename from beast/module/asio/async/AsyncObject.h rename to beast/module/asio/AsyncObject.h index cc36049b73..9ba4b33e49 100644 --- a/beast/module/asio/async/AsyncObject.h +++ b/beast/module/asio/AsyncObject.h @@ -20,6 +20,9 @@ #ifndef BEAST_ASIO_ASYNCOBJECT_H_INCLUDED #define BEAST_ASIO_ASYNCOBJECT_H_INCLUDED +#include +#include + namespace beast { namespace asio { @@ -34,7 +37,7 @@ public: ~AsyncObject () { // Destroying the object with I/O pending? Not a clean exit! - bassert (m_pending.get() == 0); + assert (m_pending.get() == 0); } /** RAII container that maintains the count of pending I/O. diff --git a/beast/module/asio/system/BoostIncludes.h b/beast/module/asio/BoostIncludes.h similarity index 100% rename from beast/module/asio/system/BoostIncludes.h rename to beast/module/asio/BoostIncludes.h diff --git a/beast/module/asio/http/HTTPField.cpp b/beast/module/asio/HTTPField.cpp similarity index 97% rename from beast/module/asio/http/HTTPField.cpp rename to beast/module/asio/HTTPField.cpp index 9a26c5f4eb..59f0be7908 100644 --- a/beast/module/asio/http/HTTPField.cpp +++ b/beast/module/asio/HTTPField.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#include + namespace beast { HTTPField::HTTPField () diff --git a/beast/module/asio/http/HTTPField.h b/beast/module/asio/HTTPField.h similarity index 100% rename from beast/module/asio/http/HTTPField.h rename to beast/module/asio/HTTPField.h diff --git a/beast/module/asio/http/HTTPHeaders.cpp b/beast/module/asio/HTTPHeaders.cpp similarity index 98% rename from beast/module/asio/http/HTTPHeaders.cpp rename to beast/module/asio/HTTPHeaders.cpp index ce865f7a76..c7c78f4c8f 100644 --- a/beast/module/asio/http/HTTPHeaders.cpp +++ b/beast/module/asio/HTTPHeaders.cpp @@ -17,6 +17,7 @@ */ //============================================================================== +#include #include namespace beast { diff --git a/beast/module/asio/http/HTTPHeaders.h b/beast/module/asio/HTTPHeaders.h similarity index 98% rename from beast/module/asio/http/HTTPHeaders.h rename to beast/module/asio/HTTPHeaders.h index e89dd3df3f..f796dfd4d7 100644 --- a/beast/module/asio/http/HTTPHeaders.h +++ b/beast/module/asio/HTTPHeaders.h @@ -20,7 +20,7 @@ #ifndef BEAST_ASIO_HTTPHEADERS_H_INCLUDED #define BEAST_ASIO_HTTPHEADERS_H_INCLUDED -#include +#include #include #include diff --git a/beast/module/asio/http/HTTPMessage.cpp b/beast/module/asio/HTTPMessage.cpp similarity index 97% rename from beast/module/asio/http/HTTPMessage.cpp rename to beast/module/asio/HTTPMessage.cpp index 43bba806b9..84379e7ef6 100644 --- a/beast/module/asio/http/HTTPMessage.cpp +++ b/beast/module/asio/HTTPMessage.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#include + namespace beast { HTTPMessage::HTTPMessage (HTTPVersion const& version_, diff --git a/beast/module/asio/http/HTTPMessage.h b/beast/module/asio/HTTPMessage.h similarity index 96% rename from beast/module/asio/http/HTTPMessage.h rename to beast/module/asio/HTTPMessage.h index 4119186c1b..81e415d1a5 100644 --- a/beast/module/asio/http/HTTPMessage.h +++ b/beast/module/asio/HTTPMessage.h @@ -20,8 +20,8 @@ #ifndef BEAST_ASIO_HTTPMESSAGE_H_INCLUDED #define BEAST_ASIO_HTTPMESSAGE_H_INCLUDED -#include -#include +#include +#include #include #include diff --git a/beast/module/asio/http/HTTPParser.cpp b/beast/module/asio/HTTPParser.cpp similarity index 96% rename from beast/module/asio/http/HTTPParser.cpp rename to beast/module/asio/HTTPParser.cpp index ae861e5b90..c435953486 100644 --- a/beast/module/asio/http/HTTPParser.cpp +++ b/beast/module/asio/HTTPParser.cpp @@ -17,6 +17,9 @@ */ //============================================================================== +#include +#include + namespace beast { HTTPParser::HTTPParser (Type type) diff --git a/beast/module/asio/http/HTTPParser.h b/beast/module/asio/HTTPParser.h similarity index 96% rename from beast/module/asio/http/HTTPParser.h rename to beast/module/asio/HTTPParser.h index 6532ee6cd0..1a77fed798 100644 --- a/beast/module/asio/http/HTTPParser.h +++ b/beast/module/asio/HTTPParser.h @@ -20,8 +20,8 @@ #ifndef BEAST_ASIO_HTTPPARSER_H_INCLUDED #define BEAST_ASIO_HTTPPARSER_H_INCLUDED -#include -#include +#include +#include namespace beast { diff --git a/beast/module/asio/http/HTTPParserImpl.h b/beast/module/asio/HTTPParserImpl.h similarity index 98% rename from beast/module/asio/http/HTTPParserImpl.h rename to beast/module/asio/HTTPParserImpl.h index 189d56890c..6d9cd6d9ca 100644 --- a/beast/module/asio/http/HTTPParserImpl.h +++ b/beast/module/asio/HTTPParserImpl.h @@ -20,6 +20,9 @@ #ifndef BEAST_HTTPPARSERIMPL_H_INCLUDED #define BEAST_HTTPPARSERIMPL_H_INCLUDED +#include +#include + namespace beast { class HTTPParserImpl diff --git a/beast/module/asio/http/HTTPRequest.cpp b/beast/module/asio/HTTPRequest.cpp similarity index 97% rename from beast/module/asio/http/HTTPRequest.cpp rename to beast/module/asio/HTTPRequest.cpp index c13f7d81c1..ae2ed6867e 100644 --- a/beast/module/asio/http/HTTPRequest.cpp +++ b/beast/module/asio/HTTPRequest.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#include + namespace beast { HTTPRequest::HTTPRequest ( diff --git a/beast/module/asio/http/HTTPRequest.h b/beast/module/asio/HTTPRequest.h similarity index 97% rename from beast/module/asio/http/HTTPRequest.h rename to beast/module/asio/HTTPRequest.h index 83aed4793c..afffec5afc 100644 --- a/beast/module/asio/http/HTTPRequest.h +++ b/beast/module/asio/HTTPRequest.h @@ -20,7 +20,7 @@ #ifndef BEAST_ASIO_HTTPREQUEST_H_INCLUDED #define BEAST_ASIO_HTTPREQUEST_H_INCLUDED -#include +#include namespace beast { diff --git a/beast/module/asio/http/HTTPRequestParser.cpp b/beast/module/asio/HTTPRequestParser.cpp similarity index 96% rename from beast/module/asio/http/HTTPRequestParser.cpp rename to beast/module/asio/HTTPRequestParser.cpp index 0647bf5016..79c9a4c343 100644 --- a/beast/module/asio/http/HTTPRequestParser.cpp +++ b/beast/module/asio/HTTPRequestParser.cpp @@ -17,7 +17,7 @@ */ //============================================================================== -//#include "HTTPRequestParser.h" +#include namespace beast { diff --git a/beast/module/asio/http/HTTPRequestParser.h b/beast/module/asio/HTTPRequestParser.h similarity index 97% rename from beast/module/asio/http/HTTPRequestParser.h rename to beast/module/asio/HTTPRequestParser.h index 0f7510d9bf..2c5cb6ff89 100644 --- a/beast/module/asio/http/HTTPRequestParser.h +++ b/beast/module/asio/HTTPRequestParser.h @@ -20,7 +20,7 @@ #ifndef BEAST_HTTP_REQUESTPARSER_H_INCLUDED #define BEAST_HTTP_REQUESTPARSER_H_INCLUDED -#include +#include namespace beast { diff --git a/beast/module/asio/http/HTTPResponse.cpp b/beast/module/asio/HTTPResponse.cpp similarity index 97% rename from beast/module/asio/http/HTTPResponse.cpp rename to beast/module/asio/HTTPResponse.cpp index b4df452ba3..227ec9acc1 100644 --- a/beast/module/asio/http/HTTPResponse.cpp +++ b/beast/module/asio/HTTPResponse.cpp @@ -17,6 +17,8 @@ */ //============================================================================== +#include + namespace beast { HTTPResponse::HTTPResponse ( diff --git a/beast/module/asio/http/HTTPResponse.h b/beast/module/asio/HTTPResponse.h similarity index 97% rename from beast/module/asio/http/HTTPResponse.h rename to beast/module/asio/HTTPResponse.h index b7ee9e98a7..a0a22a012b 100644 --- a/beast/module/asio/http/HTTPResponse.h +++ b/beast/module/asio/HTTPResponse.h @@ -20,6 +20,8 @@ #ifndef BEAST_ASIO_HTTPRESPONSE_H_INCLUDED #define BEAST_ASIO_HTTPRESPONSE_H_INCLUDED +#include + namespace beast { class HTTPResponse : public HTTPMessage diff --git a/beast/module/asio/http/HTTPResponseParser.cpp b/beast/module/asio/HTTPResponseParser.cpp similarity index 96% rename from beast/module/asio/http/HTTPResponseParser.cpp rename to beast/module/asio/HTTPResponseParser.cpp index b5e5857428..a20a414a79 100644 --- a/beast/module/asio/http/HTTPResponseParser.cpp +++ b/beast/module/asio/HTTPResponseParser.cpp @@ -17,7 +17,7 @@ */ //============================================================================== -//#include "HTTPResponseParser.h" +#include namespace beast { diff --git a/beast/module/asio/http/HTTPResponseParser.h b/beast/module/asio/HTTPResponseParser.h similarity index 97% rename from beast/module/asio/http/HTTPResponseParser.h rename to beast/module/asio/HTTPResponseParser.h index 4db08949e7..12ce69a7b9 100644 --- a/beast/module/asio/http/HTTPResponseParser.h +++ b/beast/module/asio/HTTPResponseParser.h @@ -20,7 +20,7 @@ #ifndef BEAST_HTTP_RESPONSEPARSER_H_INCLUDED #define BEAST_HTTP_RESPONSEPARSER_H_INCLUDED -#include +#include namespace beast { diff --git a/beast/module/asio/http/HTTPVersion.cpp b/beast/module/asio/HTTPVersion.cpp similarity index 100% rename from beast/module/asio/http/HTTPVersion.cpp rename to beast/module/asio/HTTPVersion.cpp diff --git a/beast/module/asio/http/HTTPVersion.h b/beast/module/asio/HTTPVersion.h similarity index 100% rename from beast/module/asio/http/HTTPVersion.h rename to beast/module/asio/HTTPVersion.h diff --git a/beast/module/asio/system/OpenSSLIncludes.h b/beast/module/asio/OpenSSLIncludes.h similarity index 100% rename from beast/module/asio/system/OpenSSLIncludes.h rename to beast/module/asio/OpenSSLIncludes.h diff --git a/beast/module/asio/asio.h b/beast/module/asio/asio.h deleted file mode 100644 index 81d85f1041..0000000000 --- a/beast/module/asio/asio.h +++ /dev/null @@ -1,75 +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_ASIO_MODULE_H_INCLUDED -#define BEAST_ASIO_MODULE_H_INCLUDED - -// Must come before boost includes to fix the bost placeholders. -#include - -// This module requires boost and possibly OpenSSL -#include - -#include - -#include - -// Order matters -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif - diff --git a/beast/module/asio/asio.unity.cpp b/beast/module/asio/asio.unity.cpp index d67d116b27..344c9901fc 100644 --- a/beast/module/asio/asio.unity.cpp +++ b/beast/module/asio/asio.unity.cpp @@ -21,36 +21,12 @@ #include #endif -#include - -#include - -#include - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/beast/module/asio/basics/ContentBodyBuffer.cpp b/beast/module/asio/basics/ContentBodyBuffer.cpp deleted file mode 100644 index 006ee52166..0000000000 --- a/beast/module/asio/basics/ContentBodyBuffer.cpp +++ /dev/null @@ -1,101 +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. -*/ -//============================================================================== - -ContentBodyBuffer::ContentBodyBuffer (size_type blocksize) - : m_blocksize (blocksize) - , m_size (0) -{ -} - -ContentBodyBuffer::~ContentBodyBuffer () -{ - for (Handles::iterator iter (m_handles.begin()); - iter != m_handles.end(); ++iter) - { - void* const buffer (*iter); - std::free (buffer); - } -} - -void ContentBodyBuffer::swapWith (ContentBodyBuffer& other) -{ - std::swap (m_blocksize, other.m_blocksize); - std::swap (m_size, other.m_size); - m_handles.swap (other.m_handles); -} - -void ContentBodyBuffer::commit (size_type n) -{ - m_size += n; - bassert (m_size <= m_handles.size () * m_blocksize); -} - -ConstBuffers ContentBodyBuffer::data () const -{ - size_type n (m_size); - std::vector v; - v.reserve ((m_size + m_blocksize - 1) / m_blocksize); - for (Handles::const_iterator iter (m_handles.begin()); - iter != m_handles.end() && n > 0; ++iter) - { - size_type const amount (std::min (n, m_blocksize)); - v.push_back (MutableBuffer (*iter, amount)); - n -= amount; - } - return ConstBuffers (v); -} - -ContentBodyBuffer::size_type ContentBodyBuffer::size () const -{ - return m_size; -} - -MutableBuffers ContentBodyBuffer::prepare (size_type n) -{ - reserve (n); - std::vector v; - size_type offset (m_size % m_blocksize); - for (Handles::iterator iter = m_handles.begin () + (m_size / m_blocksize); - iter != m_handles.end () && n > 0; ++iter) - { - size_type const amount (std::min (n, m_blocksize - offset)); - v.push_back (MutableBuffer (*iter, amount)); - n -= amount; - offset = 0; - } - return MutableBuffers (v); -} - -void ContentBodyBuffer::reserve (size_type n) -{ - size_type count ((m_size + n + m_blocksize - 1) / m_blocksize); - if (count > m_handles.size ()) - for (count -= m_handles.size (); count-- > 0;) - m_handles.push_back (std::malloc (m_blocksize)); -} - -void ContentBodyBuffer::shrink_to_fit () -{ - size_type const count ((m_size + m_blocksize - 1) / m_blocksize); - while (m_handles.size () > count) - { - std::free (m_handles.back ()); - m_handles.erase (m_handles.end () - 1); - } -} \ No newline at end of file diff --git a/beast/module/asio/basics/ContentBodyBuffer.h b/beast/module/asio/basics/ContentBodyBuffer.h deleted file mode 100644 index 63c51d9d7e..0000000000 --- a/beast/module/asio/basics/ContentBodyBuffer.h +++ /dev/null @@ -1,78 +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_ASIO_BASICS_CONTENTBODYBUFFER_H_INCLUDED -#define BEAST_ASIO_BASICS_CONTENTBODYBUFFER_H_INCLUDED - -/** Dynamic storage optimized for a large Content-Body of unknown size. - This comes at the expense of discontiguous storage of the segments. - We derive from SharedObject to make transfer of ownership inexpensive. -*/ -class ContentBodyBuffer -{ -public: - enum - { - defaultBlocksize = 32 * 1024 - }; - - typedef std::size_t size_type; - typedef ConstBuffers const_buffers_tyoe; - typedef MutableBuffers mutable_buffers_type; - - explicit ContentBodyBuffer (size_type blocksize = defaultBlocksize); - - ~ContentBodyBuffer (); - - /** Swap the contents of this buffer with another. - This is the preferred way to transfer ownership. - */ - void swapWith (ContentBodyBuffer& other); - - /** Move bytes from the output to the input sequence. - This will invalidate references to buffers. - */ - void commit (size_type n); - - /** Returns a buffer to the input sequence. */ - ConstBuffers data () const; - - /** Returns the size of the input sequence. */ - size_type size () const; - - /** Reserve space in the output sequence. - This also returns a buffer suitable for writing. - */ - MutableBuffers prepare (size_type n); - - /** Reserve space in the output sequence. */ - void reserve (size_type n); - - /** Release memory while preserving the input sequence. */ - void shrink_to_fit (); - -private: - typedef std::vector Handles; - - size_type m_blocksize; - size_type m_size; - Handles m_handles; -}; - -#endif diff --git a/beast/module/asio/basics/FixedInputBuffer.h b/beast/module/asio/basics/FixedInputBuffer.h deleted file mode 100644 index c260dc0ed0..0000000000 --- a/beast/module/asio/basics/FixedInputBuffer.h +++ /dev/null @@ -1,202 +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_ASIO_BASICS_FIXEDINPUTBUFFER_H_INCLUDED -#define BEAST_ASIO_BASICS_FIXEDINPUTBUFFER_H_INCLUDED - -#include -#include - -namespace beast { -namespace asio { - -/** Represents a small, fixed size buffer. - This provides a convenient interface for doing a bytewise - verification/reject test on a handshake protocol. -*/ -/** @{ */ -class FixedInputBuffer -{ -protected: - struct CtorParams - { - CtorParams (std::uint8_t const* begin_, std::size_t bytes_) - : begin (begin_) - , bytes (bytes_) - { - } - - std::uint8_t const* begin; - std::size_t bytes; - }; - - FixedInputBuffer (CtorParams const& params) - : m_begin (params.begin) - , m_iter (m_begin) - , m_end (m_begin + params.bytes) - { - } - -public: - FixedInputBuffer (FixedInputBuffer const& other) - : m_begin (other.m_begin) - , m_iter (other.m_iter) - , m_end (other.m_end) - { - } - - FixedInputBuffer& operator= (FixedInputBuffer const& other) - { - m_begin = other.m_begin; - m_iter = other.m_iter; - m_end = other.m_end; - return *this; - } - - // Returns the number of bytes consumed - std::size_t used () const noexcept - { - return m_iter - m_begin; - } - - // Returns the size of what's remaining - std::size_t size () const noexcept - { - return m_end - m_iter; - } - - void const* peek (std::size_t bytes) - { - return peek_impl (bytes, nullptr); - } - - template - bool peek (T* t) const noexcept - { - return peek_impl (sizeof (T), t) != nullptr; - } - - bool consume (std::size_t bytes) noexcept - { - return read_impl (bytes, nullptr) != nullptr; - } - - bool read (std::size_t bytes) noexcept - { - return read_impl (bytes, nullptr) != nullptr; - } - - template - bool read (T* t) noexcept - { - return read_impl (sizeof (T), t) != nullptr; - } - - std::uint8_t operator[] (std::size_t index) const noexcept - { - bassert (index >= 0 && index < size ()); - return m_iter [index]; - } - - // Reads an integraltype in network byte order - template - bool readNetworkInteger (IntegerType* value) - { - // Must be an integral type! - // not available in all versions of std:: unfortunately - //static_bassert (std::is_integral ::value); - IntegerType networkValue; - if (! read (&networkValue)) - return false; - *value = fromNetworkByteOrder (networkValue); - return true; - } - -protected: - void const* peek_impl (std::size_t bytes, void* buffer) const noexcept - { - if (size () >= bytes) - { - if (buffer != nullptr) - memcpy (buffer, m_iter, bytes); - return m_iter; - } - return nullptr; - } - - void const* read_impl (std::size_t bytes, void* buffer) noexcept - { - if (size () >= bytes) - { - if (buffer != nullptr) - memcpy (buffer, m_iter, bytes); - void const* data = m_iter; - m_iter += bytes; - return data; - } - return nullptr; - } - -private: - std::uint8_t const* m_begin; - std::uint8_t const* m_iter; - std::uint8_t const* m_end; -}; - -//------------------------------------------------------------------------------ - -template -class FixedInputBufferSize : public FixedInputBuffer -{ -protected: - struct SizedCtorParams - { - template - SizedCtorParams (ConstBufferSequence const& buffers, Storage& storage) - { - boost::asio::mutable_buffer buffer (boost::asio::buffer (storage)); - data = boost::asio::buffer_cast (buffer); - bytes = boost::asio::buffer_copy (buffer, buffers); - } - - operator CtorParams () const noexcept - { - return CtorParams (data, bytes); - } - - std::uint8_t const* data; - std::size_t bytes; - }; - -public: - template - explicit FixedInputBufferSize (ConstBufferSequence const& buffers) - : FixedInputBuffer (SizedCtorParams (buffers, m_storage)) - { - } - -private: - std::array m_storage; - boost::asio::mutable_buffer m_buffer; -}; - -} -} - -#endif diff --git a/beast/module/asio/basics/PeerRole.cpp b/beast/module/asio/basics/PeerRole.cpp deleted file mode 100644 index bdc1dd5960..0000000000 --- a/beast/module/asio/basics/PeerRole.cpp +++ /dev/null @@ -1,50 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -PeerRole::PeerRole (role_t role) - : m_role (role) -{ -} - -String PeerRole::name () const noexcept -{ - if (m_role == server) - return "server"; - return "client"; -} - -bool PeerRole::operator== (role_t role) const noexcept -{ - return m_role == role; -} - -#if 0 -PeerRole::operator abstract_socket::handshake_type () const noexcept -{ - if (m_role == server) - return abstract_socket::server; - return abstract_socket::client; -} -#endif - -} -} diff --git a/beast/module/asio/basics/PeerRole.h b/beast/module/asio/basics/PeerRole.h deleted file mode 100644 index d1175a66c9..0000000000 --- a/beast/module/asio/basics/PeerRole.h +++ /dev/null @@ -1,46 +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_ASIO_BASICS_PEERROLE_H_INCLUDED -#define BEAST_ASIO_BASICS_PEERROLE_H_INCLUDED - -namespace beast { -namespace asio { - -/** Identifies if the peer is a client or a server. */ -struct PeerRole -{ - enum role_t - { - client, - server - }; - - PeerRole (role_t role); - String name () const noexcept; - bool operator== (role_t role) const noexcept; - -private: - role_t m_role; -}; - -} -} - -#endif diff --git a/beast/module/asio/basics/SSLContext.cpp b/beast/module/asio/basics/SSLContext.cpp deleted file mode 100644 index b845d2cf1b..0000000000 --- a/beast/module/asio/basics/SSLContext.cpp +++ /dev/null @@ -1,33 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -SSLContext::SSLContext (ContextType& context) - : m_context (context) -{ -} - -SSLContext::~SSLContext () -{ -} - -} -} diff --git a/beast/module/asio/basics/SSLContext.h b/beast/module/asio/basics/SSLContext.h deleted file mode 100644 index dabe56b196..0000000000 --- a/beast/module/asio/basics/SSLContext.h +++ /dev/null @@ -1,72 +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_ASIO_BASICS_SSLCONTEXT_H_INCLUDED -#define BEAST_ASIO_BASICS_SSLCONTEXT_H_INCLUDED - -#include - -namespace beast { -namespace asio { - -/** Simple base class for passing a context around. - This lets derived classes hide their implementation from the headers. -*/ -class SSLContext -{ -public: - virtual ~SSLContext (); - - // Saves typing - typedef boost::asio::ssl::context ContextType; - - inline ContextType& get () noexcept - { - return m_context; - } - - inline ContextType const& get () const noexcept - { - return m_context; - } - - // implicit conversion - inline operator ContextType& () noexcept - { - return get (); - } - - inline operator ContextType const& () const noexcept - { - return get (); - } - -protected: - explicit SSLContext (ContextType& context); - - SSLContext(SSLContext const&) = delete; - SSLContext& operator= (SSLContext const&) = delete; - - ContextType& m_context; -}; - -} -} - -#endif diff --git a/beast/module/asio/http/HTTPClientType.cpp b/beast/module/asio/http/HTTPClientType.cpp deleted file mode 100644 index 4db0862d09..0000000000 --- a/beast/module/asio/http/HTTPClientType.cpp +++ /dev/null @@ -1,693 +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. -*/ -//============================================================================== - -#include -#include -#include -#include -#include // - -namespace beast { -namespace asio { - -class HTTPClientType : public HTTPClientBase -{ -public: - class Session; - - struct State - { - List list; - }; - - typedef SharedData SharedState; - - SharedState m_state; - Journal m_journal; - double m_timeoutSeconds; - std::size_t m_messageLimitBytes; - std::size_t m_bufferSize; - boost::asio::io_service m_io_service; - WaitableEvent m_stopped; - - //-------------------------------------------------------------------------- - - HTTPClientType ( - Journal journal, - double timeoutSeconds, - std::size_t messageLimitBytes, - std::size_t bufferSize) - : m_journal (journal) - , m_timeoutSeconds (timeoutSeconds) - , m_messageLimitBytes (messageLimitBytes) - , m_bufferSize (bufferSize) - , m_stopped (true, true) // manual reset, initially signaled - { - } - - HTTPClientType(HTTPClientType const&) = delete; - HTTPClientType& operator= (HTTPClientType const&) = delete; - - ~HTTPClientType () - { - cancel(); - wait(); - } - - result_type get (URL const& url) - { - result_type result; - boost::asio::io_service io_service; - async_get (io_service, url, std::bind ( - &HTTPClientType::handle_get, std::placeholders::_1, &result)); - io_service.run (); - return result; - } - - void async_get (boost::asio::io_service& io_service, URL const& url, - asio::shared_handler handler) - { - new Session (*this, io_service, url, - handler, m_timeoutSeconds, m_messageLimitBytes, m_bufferSize); - } - - void cancel () - { - SharedState::Access state (m_state); - for (List ::iterator iter (state->list.begin()); - iter != state->list.end(); ++iter) - iter->cancel(); - } - - void wait() - { - m_stopped.wait(); - } - - //-------------------------------------------------------------------------- - - void add (Session& session) - { - SharedState::Access state (m_state); - if (state->list.empty()) - m_stopped.reset(); - state->list.push_back (session); - } - - void remove (Session& session) - { - SharedState::Access state (m_state); - state->list.erase (state->list.iterator_to (session)); - if (state->list.empty()) - m_stopped.signal(); - } - - static void handle_get (result_type const& result, result_type* dest) - { - *dest = result; - } - - Journal journal() const - { - return m_journal; - } - - boost::asio::io_service& get_io_service() - { - return m_io_service; - } - - //-------------------------------------------------------------------------- - - /** Helper function to get a const_buffer from a String. */ - static boost::asio::const_buffers_1 stringBuffer (String const& s) - { - return boost::asio::const_buffers_1 (s.getCharPointer (), s.length ()); - } - - /** Helper function to fill out a Query from a URL. */ - template - static Query queryFromURL (URL const& url) - { - if (url.port () != 0) - { - return Query ( - url.host(), - url.port_string(), - Query::numeric_service); - } - - return Query ( - url.host(), - url.scheme()); - } - - //-------------------------------------------------------------------------- - - class Session - : public SharedObject - , public List ::Node - { - public: - typedef SharedPtr Ptr; - typedef boost::asio::ip::tcp Protocol; - typedef boost::system::error_code error_code; - typedef HTTPClientBase::error_type error_type; - typedef HTTPClientBase::value_type value_type; - typedef HTTPClientBase::result_type result_type; - - typedef Protocol::resolver resolver; - typedef Protocol::socket socket; - typedef resolver::query query; - typedef resolver::iterator iterator; - typedef iterator::value_type resolver_entry; - - HTTPClientType& m_owner; - boost::asio::io_service& m_io_service; - boost::asio::io_service::strand m_strand; - boost::asio::deadline_timer m_timer; - resolver m_resolver; - socket m_socket; - asio::shared_handler m_handler; - - URL m_url; - boost::asio::ssl::context m_context; - MemoryBlock m_buffer; - HTTPResponseParser m_parser; - std::size_t m_messageLimitBytes; - std::size_t m_bytesReceived; - - String m_get_string; - WaitableEvent m_done; - std::unique_ptr m_stream; - - struct State - { - State () : complete (false) - { - } - - bool complete; - error_code error; - SharedPtr response; - }; - typedef SharedData SharedState; - SharedState m_state; - - //---------------------------------------------------------------------- - - Session (HTTPClientType& owner, - boost::asio::io_service& io_service, - URL const& url, - asio::shared_handler const& handler, - double timeoutSeconds, - std::size_t messageLimitBytes, - std::size_t bufferSize) - : m_owner (owner) - , m_io_service (io_service) - , m_strand (io_service) - , m_timer (io_service) - , m_resolver (io_service) - , m_socket (io_service) - , m_handler (handler) - , m_url (url) - , m_context (boost::asio::ssl::context::sslv23) - , m_buffer (bufferSize) - , m_messageLimitBytes (messageLimitBytes) - , m_bytesReceived (0) - { - m_owner.add (*this); - - // Configure the SSL context for certificate verification - m_context.set_default_verify_paths (); - m_context.set_options ( - boost::asio::ssl::context::no_sslv2 | - boost::asio::ssl::context::no_sslv3 | - boost::asio::ssl::context::single_dh_use | - boost::asio::ssl::context::default_workarounds); - //m_context.set_verify_mode (boost::asio::ssl::verify_peer); - - // Set the timer if a timeout is requested - if (timeoutSeconds > 0) - { - m_timer.expires_from_now ( - boost::posix_time::milliseconds ( - long (timeoutSeconds * 1000))); - - m_timer.async_wait (m_strand.wrap (asio::wrap_handler ( - std::bind (&Session::handle_timer, Ptr(this), - asio::placeholders::error), m_handler))); - } - - // Start the operation on an io_service thread - io_service.dispatch (m_strand.wrap (asio::wrap_handler ( - std::bind (&Session::handle_start, Ptr(this)), m_handler))); - } - - ~Session () - { - State result; - { - SharedState::ConstAccess state (m_state); - result = *state; - } - - m_io_service.post (bind_handler (m_handler, - std::make_pair (result.error, result.response))); - - m_owner.remove (*this); - } - - //---------------------------------------------------------------------- - - // Called by the owner to cancel pending i/o. - void cancel () - { - { - SharedState::Access state (m_state); - if (! state->complete) - { - state->complete = true; - state->error = boost::asio::error::operation_aborted; - } - } - - cancel_all(); - } - - // Cancel all pending I/O - void cancel_all () - { - error_code ec; - m_timer.cancel (ec); - m_resolver.cancel (); - m_socket.cancel (ec); - m_socket.shutdown (socket::shutdown_both, ec); - } - - // Called by a completion handler when error is not eof or aborted. - void failed (error_code ec) - { - { - SharedState::Access state (m_state); - if (! state->complete) - { - state->complete = true; - state->error = ec; - state->response = nullptr; - } - } - - cancel_all(); - } - - void async_read_some () - { - boost::asio::mutable_buffers_1 buf ( - m_buffer.getData (), m_buffer.getSize ()); - - m_stream->async_read_some (buf, m_strand.wrap ( - asio::wrap_handler (std::bind (&Session::handle_read, - Ptr(this), asio::placeholders::error, - asio::placeholders::bytes_transferred), m_handler))); - } - - //---------------------------------------------------------------------- - // - // Completion handlers - // - - // Called when the operation starts - void handle_start () - { - query q (queryFromURL (m_url)); - - m_resolver.async_resolve (q, m_strand.wrap ( - asio::wrap_handler (std::bind (&Session::handle_resolve, - Ptr(this), asio::placeholders::error, - asio::placeholders::iterator), m_handler))); - } - - // Called when the timer completes - void handle_timer (error_code ec) - { - if (ec == boost::asio::error::operation_aborted) - return; - - if (ec != 0) - { - failed (ec); - return; - } - - failed (boost::system::errc::make_error_code ( - boost::system::errc::timed_out)); - } - - // Called when the resolver completes - void handle_resolve (error_code ec, iterator iter) - { - if (ec == boost::asio::error::operation_aborted) - return; - - if (ec != 0) - { - failed (ec); - return; - } - - resolver_entry const entry (*iter); - m_socket.async_connect (entry.endpoint (), m_strand.wrap ( - asio::wrap_handler (std::bind (&Session::handle_connect, - Ptr(this), asio::placeholders::error), m_handler))); - } - - // Called when the connection attempt completes - void handle_connect (error_code ec) - { - if (ec == boost::asio::error::operation_aborted) - return; - - if (ec != 0) - { - failed (ec); - return; - } - - if (m_url.scheme () == "https") - { - typedef boost::asio::ssl::stream ssl_stream; - m_stream = std::make_unique < - socket_wrapper > (m_socket, m_context); - /* - m_stream->set_verify_mode ( - boost::asio::ssl::verify_peer | - boost::asio::ssl::verify_fail_if_no_peer_cert); - */ - m_stream->async_handshake (abstract_socket::client, m_strand.wrap ( - asio::wrap_handler (std::bind (&Session::handle_handshake, - Ptr(this), asio::placeholders::error), m_handler))); - return; - } - - m_stream = std::make_unique > (m_socket); - handle_handshake (ec); - } - - // Called when the SSL handshake completes - void handle_handshake (error_code ec) - { - if (ec == boost::asio::error::operation_aborted) - return; - - if (ec != 0) - { - failed (ec); - return; - } - - m_get_string = - "GET " + m_url.path() + " HTTP/1.1\r\n" + - "Host: " + m_url.host() + "\r\n" + - "Accept: */*\r\n" + - "Connection: close\r\n\r\n"; - - boost::asio::async_write (*m_stream, stringBuffer ( - m_get_string), m_strand.wrap (asio::wrap_handler ( - std::bind (&Session::handle_write, Ptr(this), - asio::placeholders::error, - asio::placeholders::bytes_transferred), m_handler))); - - async_read_some (); - } - - // Called when the write operation completes - void handle_write (error_code ec, std::size_t) - { - if (ec == boost::asio::error::operation_aborted) - return; - - if (ec != 0) - { - failed (ec); - return; - } - - if (! m_stream->needs_handshake ()) - m_socket.shutdown (socket::shutdown_send, ec); - } - - void handle_read (error_code ec, - std::size_t bytes_transferred) - { - if (ec == boost::asio::error::operation_aborted) - return; - - if (ec != 0) - { - failed (ec); - return; - } - - m_bytesReceived += bytes_transferred; - if (m_bytesReceived > m_messageLimitBytes) - { - failed (error_code ( - boost::system::errc::invalid_argument, - boost::system::system_category ())); - return; - } - - std::size_t const bytes_parsed (m_parser.process ( - m_buffer.getData (), bytes_transferred)); - - if (m_parser.error ()) - { - failed (error_code ( - boost::system::errc::invalid_argument, - boost::system::system_category ())); - return; - } - - if (bytes_parsed != bytes_transferred) - { - failed (error_code ( - boost::system::errc::invalid_argument, - boost::system::system_category ())); - return; - } - - if (ec == boost::asio::error::eof) - m_parser.process_eof (); - - if (m_parser.finished ()) - { - if (m_stream->needs_handshake ()) - { - m_stream->async_shutdown (m_strand.wrap (asio::wrap_handler ( - std::bind (&Session::handle_shutdown, - Ptr(this), asio::placeholders::error), m_handler))); - } - else - { - handle_shutdown (error_code ()); - } - return; - } - - async_read_some (); - } - - void handle_shutdown (error_code ec) - { - if (ec == boost::asio::error::operation_aborted) - return; - - if (ec == boost::asio::error::eof) - ec = error_code(); - - if (ec != 0) - { - failed (ec); - return; - } - - { - SharedState::Access state (m_state); - if (! state->complete) - { - state->complete = true; - state->response = m_parser.response(); - } - } - - cancel_all(); - } - }; -}; - -//------------------------------------------------------------------------------ - -HTTPClientBase* HTTPClientBase::New (Journal journal, - double timeoutSeconds, std::size_t messageLimitBytes, std::size_t bufferSize) -{ - return new HTTPClientType ( - journal, timeoutSeconds, messageLimitBytes, bufferSize); -} - -//------------------------------------------------------------------------------ - -class HTTPClient_test : public unit_test::suite -{ -public: - typedef boost::system::error_code error_code; - - //-------------------------------------------------------------------------- - - class IoServiceThread : protected Thread - { - public: - explicit IoServiceThread (String name = "io_service") - : Thread (name) - { - } - - ~IoServiceThread () - { - join (); - } - - boost::asio::io_service& get_io_service () - { - return m_service; - } - - void start () - { - startThread (); - } - - void join () - { - this->waitForThreadToExit (); - } - - private: - void run () - { - m_service.run (); - } - - private: - boost::asio::io_service m_service; - }; - - //-------------------------------------------------------------------------- - - void print (HTTPMessage const& m) - { - for (int i = 0; i < m.headers().size(); ++i) - { - HTTPField const f (m.headers()[i]); - std::stringstream ss; - log << - "[ '" << f.name() << - "' , '" << f.value() + "' ]"; - } - } - - void print (HTTPClientBase::error_type error, - HTTPClientBase::value_type const& response) - { - if (error != 0) - { - log << - "HTTPClient error: '" + error.message() << "'"; - } - else if (! response.empty ()) - { - log << - "Status: " << - String::fromNumber (response->status()).toStdString(); - - print (*response); - } - else - { - log << - "HTTPClient: no response"; - } - } - - //-------------------------------------------------------------------------- - - void handle_get (HTTPClientBase::result_type result) - { - print (result.first, result.second); - } - - void testSync (String const& s, double timeoutSeconds) - { - std::unique_ptr client ( - HTTPClientBase::New (Journal(), timeoutSeconds)); - - HTTPClientBase::result_type const& result ( - client->get (parse_URL (s.toStdString ()).second)); - - print (result.first, result.second); - } - - void testAsync (String const& s, double timeoutSeconds) - { - IoServiceThread t; - std::unique_ptr client ( - HTTPClientBase::New (Journal(), timeoutSeconds)); - - client->async_get (t.get_io_service (), parse_URL (s.toStdString ()).second, - std::bind (&HTTPClient_test::handle_get, this, - std::placeholders::_1)); - - t.start (); - t.join (); - } - - //-------------------------------------------------------------------------- - - void run () - { - testSync ( - "http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference.html", - 5); - - testAsync ( - "http://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference.html", - 5); - - testAsync ( - "https://www.boost.org/doc/libs/1_54_0/doc/html/boost_asio/reference.html", - 5); - - pass (); - } -}; - -BEAST_DEFINE_TESTSUITE_MANUAL(HTTPClient,beast_asio,beast); - -} -} diff --git a/beast/module/asio/http/HTTPClientType.h b/beast/module/asio/http/HTTPClientType.h deleted file mode 100644 index aac69eff79..0000000000 --- a/beast/module/asio/http/HTTPClientType.h +++ /dev/null @@ -1,68 +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_ASIO_HTTPCLIENTTYPE_H_INCLUDED -#define BEAST_ASIO_HTTPCLIENTTYPE_H_INCLUDED - -#include - -#include - -namespace beast { -namespace asio { - -class HTTPClientBase -{ -public: - typedef boost::system::error_code error_type; - typedef SharedPtr value_type; - typedef std::pair result_type; - - static HTTPClientBase* New ( - Journal journal = Journal(), - double timeoutSeconds = 30, - std::size_t messageLimitBytes = 256 * 1024, - std::size_t bufferSize = 16 * 1024); - - /** Destroy the client. - This will cancel any pending i/o and block until all completion - handlers have been called. - */ - virtual ~HTTPClientBase () { } - - virtual result_type get (URL const& url) = 0; - - /** Perform an asynchronous get on the specified URL. - Handler will be called with this signature: - void (result_type) - */ - virtual void async_get (boost::asio::io_service& io_service, - URL const& url, asio::shared_handler handler) = 0; - - /** Cancel all pending asynchronous operations. */ - virtual void cancel() = 0; - - /** Block until all asynchronous i/o completes. */ - virtual void wait() = 0; -}; - -} -} - -#endif diff --git a/beast/module/asio/protocol/HandshakeDetectLogic.h b/beast/module/asio/protocol/HandshakeDetectLogic.h deleted file mode 100644 index 77b6d07368..0000000000 --- a/beast/module/asio/protocol/HandshakeDetectLogic.h +++ /dev/null @@ -1,147 +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_ASIO_HANDSHAKE_HANDSHAKEDETECTLOGIC_H_INCLUDED -#define BEAST_ASIO_HANDSHAKE_HANDSHAKEDETECTLOGIC_H_INCLUDED - -namespace beast { -namespace asio { - -class HandshakeDetectLogic -{ -public: - HandshakeDetectLogic () - : m_finished (false) - , m_success (false) - { - } - - /** How many bytes maximum we might need. - - This is the largest number of bytes that the detector - might need in order to come to a conclusion about - whether or not the handshake is a match. Depending - on the data, it could come to that conclusion sooner - though. - - Use read_some instead of read so that the detect logic - can reject the handshake sooner if possible. - */ - virtual std::size_t max_needed () = 0; - - /** How many bytes the handshake consumes. - If the detector processes the entire handshake this will - be non zero. The SSL detector would return 0, since we - want all the existing bytes to be passed on. - */ - virtual std::size_t bytes_consumed () = 0; - - /** Return true if we have enough data to form a conclusion. - */ - bool finished () const noexcept - { - return m_finished; - } - - /** Return true if we came to a conclusion and the data matched. - */ - bool success () const noexcept - { - return m_finished && m_success; - } - -protected: - void conclude (bool success = true) - { - m_finished = true; - m_success = success; - } - - void fail () - { - conclude (false); - } - -private: - bool m_finished; - bool m_success; -}; - -//------------------------------------------------------------------------------ - -/** Wraps the logic and exports it as an abstract interface. -*/ -template -class HandshakeDetectLogicType -{ -public: - typedef Logic LogicType; - typedef typename Logic::arg_type arg_type; - - explicit HandshakeDetectLogicType (arg_type const& arg = arg_type ()) - : m_logic (arg) - { - } - - LogicType& get () - { - return m_logic; - } - - std::size_t max_needed () - { - return m_logic.max_needed (); - } - - std::size_t bytes_consumed () - { - return m_logic.bytes_consumed (); - } - - bool finished () - { - return m_logic.finished (); - } - - /** If finished is true, this tells us if the handshake was detected. - */ - bool success () - { - return m_logic.success (); - } - - /** Analyze the buffer to match the Handshake. - Returns `true` if the analysis is complete. - */ - template - bool analyze (ConstBufferSequence const& buffer) - { - bassert (! m_logic.finished ()); - m_logic.analyze (buffer); - return m_logic.finished (); - } - -private: - Logic m_logic; -}; - -} -} - -#endif diff --git a/beast/module/asio/protocol/HandshakeDetectLogicPROXY.cpp b/beast/module/asio/protocol/HandshakeDetectLogicPROXY.cpp deleted file mode 100644 index 845fcf36a7..0000000000 --- a/beast/module/asio/protocol/HandshakeDetectLogicPROXY.cpp +++ /dev/null @@ -1,24 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -} -} diff --git a/beast/module/asio/protocol/HandshakeDetectLogicPROXY.h b/beast/module/asio/protocol/HandshakeDetectLogicPROXY.h deleted file mode 100644 index bde44bedac..0000000000 --- a/beast/module/asio/protocol/HandshakeDetectLogicPROXY.h +++ /dev/null @@ -1,168 +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_ASIO_HANDSHAKE_HANDSHAKEDETECTLOGICPROXY_H_INCLUDED -#define BEAST_ASIO_HANDSHAKE_HANDSHAKEDETECTLOGICPROXY_H_INCLUDED - -#include -#include - -namespace beast { -namespace asio { - -/** Handshake detector for the PROXY protcol - - http://haproxy.1wt.eu/download/1.5/doc/proxy-protocol.txt -*/ -class HandshakeDetectLogicPROXY : public HandshakeDetectLogic -{ -public: - typedef int arg_type; - - enum - { - // This is for version 1. The largest number of bytes - // that we could possibly need to parse a valid handshake. - // We will reject it much sooner if there's an illegal value. - // - maxBytesNeeded = 107 // including CRLF, no null term - }; - - struct ProxyInfo - { - typedef InputParser::IPv4Address IPv4Address; - - String protocol; // "TCP4", "TCP6", "UNKNOWN" - - IPv4Address sourceAddress; - IPv4Address destAddress; - - std::uint16_t sourcePort; - std::uint16_t destPort; - }; - - explicit HandshakeDetectLogicPROXY (arg_type const&) - : m_consumed (0) - { - } - - ProxyInfo const& getInfo () const noexcept - { - return m_info; - } - - std::size_t max_needed () - { - return maxBytesNeeded; - } - - std::size_t bytes_consumed () - { - return m_consumed; - } - - template - void analyze (ConstBufferSequence const& buffer) - { - FixedInputBufferSize in (buffer); - - InputParser::State state; - - analyze_input (in, state); - - if (state.passed ()) - { - m_consumed = in.used (); - conclude (true); - } - else if (state.failed ()) - { - conclude (false); - } - } - - void analyze_input (FixedInputBuffer& in, InputParser::State& state) - { - using namespace InputParser; - - if (! match (in, "PROXY ", state)) - return; - - if (match (in, "TCP4 ")) - { - m_info.protocol = "TCP4"; - - if (! read (in, m_info.sourceAddress, state)) - return; - - if (! match (in, " ", state)) - return; - - if (! read (in, m_info.destAddress, state)) - return; - - if (! match (in, " ", state)) - return; - - UInt16Str sourcePort; - if (! read (in, sourcePort, state)) - return; - m_info.sourcePort = sourcePort.value; - - if (! match (in, " ", state)) - return; - - UInt16Str destPort; - if (! read (in, destPort, state)) - return; - m_info.destPort = destPort.value; - - if (! match (in, "\r\n", state)) - return; - - state = State::pass; - return; - } - else if (match (in, "TCP6 ")) - { - m_info.protocol = "TCP6"; - - state = State::fail; - return; - } - else if (match (in, "UNKNOWN ")) - { - m_info.protocol = "UNKNOWN"; - - state = State::fail; - return; - } - - state = State::fail; - } - -private: - std::size_t m_consumed; - ProxyInfo m_info; -}; - -} -} - -#endif diff --git a/beast/module/asio/protocol/HandshakeDetectLogicSSL2.h b/beast/module/asio/protocol/HandshakeDetectLogicSSL2.h deleted file mode 100644 index 1419242032..0000000000 --- a/beast/module/asio/protocol/HandshakeDetectLogicSSL2.h +++ /dev/null @@ -1,114 +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_ASIO_HANDSHAKE_HANDSHAKEDETECTLOGICSSL2_H_INCLUDED -#define BEAST_ASIO_HANDSHAKE_HANDSHAKEDETECTLOGICSSL2_H_INCLUDED - -namespace beast { -namespace asio { - -// Handshake for SSL 2 -// -// http://tools.ietf.org/html/rfc5246#appendix-E.2 -// -// std::uint8_t V2CipherSpec[3]; -// struct { -// std::uint16_t msg_length; -// std::uint8_t msg_type; -// Version version; Should be 'ProtocolVersion'? -// std::uint16_t cipher_spec_length; -// std::uint16_t session_id_length; -// std::uint16_t challenge_length; -// ... -// -class HandshakeDetectLogicSSL2 : public HandshakeDetectLogic -{ -public: - typedef int arg_type; - - explicit HandshakeDetectLogicSSL2 (arg_type const&) - { - } - - enum - { - bytesNeeded = 3 - }; - - std::size_t max_needed () - { - return bytesNeeded; - } - - std::size_t bytes_consumed () - { - return 0; - } - - template - void analyze (ConstBufferSequence const& buffer) - { - FixedInputBufferSize in (buffer); - - { - std::uint8_t byte; - if (! in.peek (&byte)) - return; - - // First byte must have the high bit set - // - if((byte & 0x80) != 0x80) - return fail (); - } - - // The remaining bits contain the - // length of the following data in bytes. - // - std::uint16_t msg_length; - if (! in.readNetworkInteger(&msg_length)) - return; - - // sizeof (msg_type + - // Version (ProtcolVersion?) + - // cipher_spec_length + - // session_id_length + - // challenge_length) - // - // Should be 9 or greater. - // - if (msg_length < 9) - return fail (); - - std::uint8_t msg_type; - if (! in.read (&msg_type)) - return; - - // The msg_type must be 0x01 for a version 2 ClientHello - // - if (msg_type != 0x01) - return fail (); - - conclude (); - } -}; - -} -} - -#endif diff --git a/beast/module/asio/protocol/HandshakeDetectLogicSSL3.h b/beast/module/asio/protocol/HandshakeDetectLogicSSL3.h deleted file mode 100644 index e4557fc9ff..0000000000 --- a/beast/module/asio/protocol/HandshakeDetectLogicSSL3.h +++ /dev/null @@ -1,90 +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_ASIO_HANDSHAKE_HANDSHAKEDETECTLOGICSSL3_H_INCLUDED -#define BEAST_ASIO_HANDSHAKE_HANDSHAKEDETECTLOGICSSL3_H_INCLUDED - -#include - -namespace beast { -namespace asio { - -// Handshake for SSL 3 (Also TLS 1.0 and 1.1) -// -// http://www.ietf.org/rfc/rfc2246.txt -// -// Section 7.4. Handshake protocol -// -class HandshakeDetectLogicSSL3 : public HandshakeDetectLogic -{ -public: - typedef int arg_type; // dummy - - explicit HandshakeDetectLogicSSL3 (arg_type const&) - { - } - - enum - { - bytesNeeded = 6 - }; - - std::size_t max_needed () - { - return bytesNeeded; - } - - std::size_t bytes_consumed () - { - return 0; - } - - template - void analyze (ConstBufferSequence const& buffer) - { - std::uint16_t version; - FixedInputBufferSize in (buffer); - - std::uint8_t msg_type; - if (! in.read (&msg_type)) - return; - - // msg_type must be 0x16 = "SSL Handshake" - // - if (msg_type != 0x16) - return fail (); - - if (! in.read (&version)) - return; - version = fromNetworkByteOrder (version); - - std::uint16_t length; - if (! in.read (&length)) - return; - - length = fromNetworkByteOrder (length); - - conclude (); - } -}; - -} -} - -#endif diff --git a/beast/module/asio/protocol/HandshakeDetector.h b/beast/module/asio/protocol/HandshakeDetector.h deleted file mode 100644 index eb57428317..0000000000 --- a/beast/module/asio/protocol/HandshakeDetector.h +++ /dev/null @@ -1,220 +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_ASIO_HANDSHAKE_HANDSHAKEDETECTOR_H_INCLUDED -#define BEAST_ASIO_HANDSHAKE_HANDSHAKEDETECTOR_H_INCLUDED - -#include -#include -#include -#include -#include - -#include -#include - -namespace beast { -namespace asio { - -/** A wrapper to decode the handshake data on a Stream. - - Stream must meet these requirements - - For detect: - SyncReadStream - - For async_detect: - AsyncReadStream - - Logic must meet this requirement: - HandshakeDetectLogic -*/ -template -class HandshakeDetectorType -{ -protected: - typedef boost::system::error_code error_code; - -public: - Logic& getLogic () - { - return m_logic.get (); - } - - //-------------------------------------------------------------------------- - - /** Synchronous handshake detect. - The bytes from the input sequence in the specified buffer - are used first. - */ - template - error_code detect (Stream& stream, - boost::asio::basic_streambuf & buffer) - { - typedef boost::asio::basic_streambuf BuffersType; - - error_code ec; - - do - { - m_logic.analyze (buffer.data ()); - - if (m_logic.finished ()) - { - // consume what we used (for SSL its 0) - std::size_t const consumed = m_logic.bytes_consumed (); - bassert (consumed <= buffer.size ()); - buffer.consume (consumed); - break; - } - - std::size_t const available = buffer.size (); - std::size_t const needed = m_logic.max_needed (); - - // If postcondition fails, loop will never end - if (meets_postcondition (available < needed)) - { - typename BuffersType::mutable_buffers_type buffers ( - buffer.prepare (needed - available)); - buffer.commit (stream.read_some (buffers, ec)); - } - } - while (! ec); - - return ec; - } - - //-------------------------------------------------------------------------- - - /** Asynchronous handshake detect. - The bytes from the input sequence in the specified buffer - are used first. - - DetectHandler must have this signature: - void(error_code) - */ - template - void async_detect (Stream& stream, - boost::asio::basic_streambuf & buffer, - asio::shared_handler handler) - { - typedef AsyncOp Op; - auto const op (std::make_shared (std::ref (m_logic), - std::ref (stream), std::ref (buffer), std::cref (handler))); - //op->start(); - stream.get_io_service().post (asio::wrap_handler (std::bind ( - &Op::start, op), handler)); - } - -private: - template - class AsyncOp - : public std::enable_shared_from_this > - { - public: - typedef boost::asio::basic_streambuf BuffersType; - - AsyncOp (HandshakeDetectLogicType & logic, Stream& stream, - BuffersType& buffer, asio::shared_handler < - void(error_code)> const& handler) - : m_logic (logic) - , m_stream (stream) - , m_buffer (buffer) - , m_handler (handler) - , m_continuation (false) - { - } - - // Set breakpoint to prove it gets destroyed - ~AsyncOp () - { - } - - void start() - { - async_read_some (error_code(), 0); - } - - void on_read (error_code ec, size_t bytes_transferred) - { - m_continuation = true; - async_read_some (ec, bytes_transferred); - } - - void async_read_some (error_code ec, size_t bytes_transferred) - { - if (! ec) - { - m_buffer.commit (bytes_transferred); - - m_logic.analyze (m_buffer.data ()); - - if (!m_logic.finished ()) - { - std::size_t const available = m_buffer.size (); - std::size_t const needed = m_logic.max_needed (); - - // If postcondition fails, loop will never end - if (meets_postcondition (available < needed)) - { - typename BuffersType::mutable_buffers_type buffers ( - m_buffer.prepare (needed - available)); - - m_stream.async_read_some (buffers, asio::wrap_handler ( - std::bind (&AsyncOp ::on_read, - this->shared_from_this(), asio::placeholders::error, - asio::placeholders::bytes_transferred), - m_handler, m_continuation)); - } - - return; - } - - std::size_t const consumed = m_logic.bytes_consumed (); - m_buffer.consume (consumed); - } - - // Finalize with a call to the original handler. - if (m_continuation) - { - m_handler (ec); - return; - } - // Post, otherwise we would call the - // handler from the initiating function. - m_stream.get_io_service ().post (asio::bind_handler ( - m_handler, ec)); - } - - private: - HandshakeDetectLogicType & m_logic; - Stream& m_stream; - BuffersType& m_buffer; - asio::shared_handler m_handler; - bool m_continuation; - }; - -private: - HandshakeDetectLogicType m_logic; -}; - -} -} - -#endif diff --git a/beast/module/asio/protocol/InputParser.h b/beast/module/asio/protocol/InputParser.h deleted file mode 100644 index 2e6117a77a..0000000000 --- a/beast/module/asio/protocol/InputParser.h +++ /dev/null @@ -1,395 +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_ASIO_HANDSHAKE_INPUTPARSER_H_INCLUDED -#define BEAST_ASIO_HANDSHAKE_INPUTPARSER_H_INCLUDED - -#include -#include - -#include - -namespace beast { -namespace asio { - -namespace InputParser { - -/** Tri-valued parsing state. - This is convertible to bool which means continue. - Or you can use stop() to decide if you should return. - After a stop you can use failed () to determine if parsing failed. -*/ -struct State -{ - enum State_t - { - pass, // passed the parse - fail, // failed the parse - more // didn't fail but need more bytes - }; - - State () : m_state (more) { } - - State (State_t state) : m_state (state) { } - - /** Implicit construction from bool. - If condition is true then the parse passes, else need more. - */ - State (bool condition) : m_state (condition ? pass : more) { } - - State& operator= (State_t state) { m_state = state; return *this; } - - bool eof () const noexcept { return m_state == more; } - bool stop () const noexcept { return m_state != pass; } - bool passed () const noexcept { return m_state == pass; } - bool failed () const noexcept { return m_state == fail; } - explicit operator bool() const noexcept { return m_state == pass; } - -private: - State_t m_state; -}; - -//------------------------------------------------------------------------------ - -// Shortcut to save typing. -typedef FixedInputBuffer& Input; - -/** Specializations implement the get() function. */ -template -struct Get; - -/** Specializations implement the match() function. - Default implementation of match tries to read it into a local. -*/ -template -struct Match -{ - static State func (Input in, T other) - { - T t; - State state = Get ::func (in, t); - if (state.passed ()) - { - if (t == other) - return State::pass; - return State::fail; - } - return state; - } -}; - -/** Specializations implement the peek() function. - Default implementation of peek reads and rewinds. -*/ -template -struct Peek -{ - static State func (Input in, T& t) - { - Input dup (in); - return Get ::func (dup, t); - } -}; - -//------------------------------------------------------------------------------ -// -// Free Functions -// -//------------------------------------------------------------------------------ - -// match a block of data in memory -// -static State match_buffer (Input in, void const* buffer, std::size_t bytes) -{ - bassert (bytes > 0); - if (in.size () <= 0) - return State::more; - - std::size_t const have = std::min (in.size (), bytes); - void const* data = in.peek (have); - bassert (data != nullptr); - - int const compare = memcmp (data, buffer, have); - if (compare != 0) - return State::fail; - in.consume (have); - - return have == bytes; -} - -//------------------------------------------------------------------------------ -// -// match -// - -// Returns the state -template -State match (Input in, T t) -{ - return Match ::func (in, t); -} - -// Stores the state in the argument and returns true if its a pass -template -bool match (Input in, T t, State& state) -{ - return (state = match (in, t)).passed (); -} - -//------------------------------------------------------------------------------ -// -// peek -// - -// Returns the state -template -State peek (Input in, T& t) -{ - return Peek ::func (in, t); -} - -// Stores the state in the argument and returns true if its a pass -template -bool peek (Input in, T& t, State& state) -{ - return (state = peek (in, t)).passed (); -} - -//------------------------------------------------------------------------------ -// -// read -// - -// Returns the state -template -State read (Input in, T& t) -{ - return Get ::func (in, t); -} - -// Stores the state in the argument and returns true if its a pass -template -bool read (Input in, T& t, State& state) -{ - return (state = read (in, t)).passed (); -} - -//------------------------------------------------------------------------------ -// -// Specializations for basic types -// - -template <> -struct Match -{ - static State func (Input in, char const* text) - { - return InputParser::match_buffer (in, text, strlen (text)); - } -}; - -//------------------------------------------------------------------------------ -// -// Special types and their specializations -// - -struct Digit -{ - int value; -}; - -template <> -struct Get -{ - static State func (Input in, Digit& t) - { - char c; - if (! in.peek (&c)) - return State::more; - if (! std::isdigit (c)) - return State::fail; - in.consume (1); - t.value = c - '0'; - return State::pass; - } -}; - -//------------------------------------------------------------------------------ - -// An unsigned 32 bit number expressed as a string -struct UInt32Str -{ - std::uint32_t value; -}; - -template <> -struct Get -{ - static State func (Input in, UInt32Str& t) - { - State state; - std::uint32_t value (0); - - Digit digit; - // have to have at least one digit - if (! read (in, digit, state)) - return state; - value = digit.value; - - for (;;) - { - state = peek (in, digit); - - if (state.failed ()) - { - t.value = value; - return State::pass; - } - else if (state.eof ()) - { - t.value = value; - return state; - } - - // can't have a digit following a zero - if (value == 0) - return State::fail; - - std::uint32_t newValue = (value * 10) + digit.value; - - // overflow - if (newValue < value) - return State::fail; - - value = newValue; - } - - return State::fail; - } -}; - -//------------------------------------------------------------------------------ - -// An unsigned 16 bit number expressed as a string -struct UInt16Str -{ - std::uint16_t value; -}; - -template <> -struct Get -{ - static State func (Input in, UInt16Str& t) - { - UInt32Str v; - State state = read (in, v); - if (state.passed ()) - { - if (v.value <= 65535) - { - t.value = std::uint16_t(v.value); - return State::pass; - } - return State::fail; - } - return state; - } -}; - -//------------------------------------------------------------------------------ - -// An unsigned 8 bit number expressed as a string -struct UInt8Str -{ - std::uint8_t value; -}; - -template <> -struct Get -{ - static State func (Input in, UInt8Str& t) - { - UInt32Str v; - State state = read (in, v); - if (state.passed ()) - { - if (v.value <= 255) - { - t.value = std::uint8_t(v.value); - return State::pass; - } - return State::fail; - } - return state; - } -}; - -//------------------------------------------------------------------------------ - -// An dotted IPv4 address -struct IPv4Address -{ - std::uint8_t value [4]; - - String toString () const - { - return String::fromNumber (value [0]) + "." + - String::fromNumber (value [1]) + "." + - String::fromNumber (value [2]) + "." + - String::fromNumber (value [3]); - } -}; - -template <> -struct Get -{ - static State func (Input in, IPv4Address& t) - { - State state; - UInt8Str digit [4]; - if (! read (in, digit [0], state)) - return state; - if (! match (in, ".", state)) - return state; - if (! read (in, digit [1], state)) - return state; - if (! match (in, ".", state)) - return state; - if (! read (in, digit [2], state)) - return state; - if (! match (in, ".", state)) - return state; - if (! read (in, digit [3], state)) - return state; - - t.value [0] = digit [0].value; - t.value [1] = digit [1].value; - t.value [2] = digit [2].value; - t.value [3] = digit [3].value; - - return State::pass; - } -}; - -} - -} -} - -#endif diff --git a/beast/module/asio/protocol/PrefilledReadStream.h b/beast/module/asio/protocol/PrefilledReadStream.h deleted file mode 100644 index 6adf0dc7e4..0000000000 --- a/beast/module/asio/protocol/PrefilledReadStream.h +++ /dev/null @@ -1,207 +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_ASIO_HANDSHAKE_PREFILLEDREADSTREAM_H_INCLUDED -#define BEAST_ASIO_HANDSHAKE_PREFILLEDREADSTREAM_H_INCLUDED - -#include // -#include - -namespace beast { -namespace asio { - -/** Front-ends a stream with a provided block of data. - - When read operations are performed on this object, bytes will first be - returned from the buffer provided on construction. When those bytes - are exhausted, read operations will then pass through to the underlying - stream. - - Write operations are all simply passed through. -*/ -template -class PrefilledReadStream -{ -protected: - typedef boost::system::error_code error_code; - - static void throw_if (error_code const& ec) - { - throw boost::system::system_error (ec); - } - -public: - PrefilledReadStream (PrefilledReadStream const&) = delete; - PrefilledReadStream& operator= (PrefilledReadStream const&) = delete; - - typedef std::remove_reference_t next_layer_type; - typedef typename next_layer_type::lowest_layer_type lowest_layer_type; - - /** Single argument constructor for when we are wrapped in something. - arg is passed through to the next layer's constructor. - */ - template - explicit PrefilledReadStream (Arg& arg) - : m_next_layer (arg) - { - } - - /** Construct with the buffer, and argument passed through. - This creates a copy of the data. The argument is passed through - to the constructor of Stream. - */ - template - PrefilledReadStream (Arg& arg, ConstBufferSequence const& buffers) - : m_next_layer (arg) - { - fill (buffers); - } - - /** Place some input into the prefilled buffer. - Note that this is in no way thread safe. The only reason this function - is here is for the case when you can't pass the buffer through the - constructor because there is another object wrapping this stream. - */ - template - void fill (ConstBufferSequence const& buffers) - { - // We don't assume the caller's buffers will - // remain valid for the lifetime of this object. - // - m_buffer.commit (boost::asio::buffer_copy ( - m_buffer.prepare (boost::asio::buffer_size (buffers)), - buffers)); - } - - next_layer_type& next_layer() - { - return m_next_layer; - } - - next_layer_type const& next_layer() const - { - return m_next_layer; - } - - lowest_layer_type& lowest_layer() - { - return m_next_layer.lowest_layer(); - } - - const lowest_layer_type& lowest_layer() const - { - return m_next_layer.lowest_layer(); - } - - boost::asio::io_service& get_io_service() - { - return m_next_layer.get_io_service(); - } - - void close() - { - error_code ec; - close (ec); - throw_if (ec); - } - - error_code close (error_code& ec) - { - // VFALCO NOTE This is questionable. We can't - // call m_next_layer.close() because Stream might not - // support that function. For example, ssl::stream has no close() - // - return lowest_layer ().close(ec); - } - - template - std::size_t read_some (MutableBufferSequence const& buffers) - { - error_code ec; - std::size_t const amount = read_some (buffers, ec); - throw_if (ec); - return amount; - } - - template - std::size_t read_some (MutableBufferSequence const& buffers, - error_code& ec) - { - if (m_buffer.size () > 0) - { - ec = error_code (); - std::size_t const bytes_transferred = boost::asio::buffer_copy ( - buffers, m_buffer.data ()); - m_buffer.consume (bytes_transferred); - return bytes_transferred; - } - return m_next_layer.read_some (buffers, ec); - } - - template - std::size_t write_some (ConstBufferSequence const& buffers) - { - error_code ec; - auto const amount (write_some (buffers, ec)); - throw_if (ec); - return amount; - } - - template - std::size_t write_some (ConstBufferSequence const& buffers, - error_code& ec) - { - return m_next_layer.write_some (buffers, ec); - } - - template - void async_read_some (MutableBufferSequence const& buffers, - ReadHandler&& handler) - { - if (m_buffer.size () > 0) - { - auto const bytes_transferred (boost::asio::buffer_copy ( - buffers, m_buffer.data ())); - m_buffer.consume (bytes_transferred); - get_io_service ().post (bind_handler ( - std::forward (handler), - error_code (), bytes_transferred)); - return; - } - m_next_layer.async_read_some (buffers, - std::forward (handler)); - } - - template - void async_write_some (ConstBufferSequence const& buffers, - WriteHandler&& handler) - { - m_next_layer.async_write_some (buffers, - std::forward (handler)); - } - -private: - Stream m_next_layer; - boost::asio::streambuf m_buffer; -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/PeerTest.cpp b/beast/module/asio/tests/PeerTest.cpp deleted file mode 100644 index 95b32fedbc..0000000000 --- a/beast/module/asio/tests/PeerTest.cpp +++ /dev/null @@ -1,110 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -PeerTest::Result::Result () - : m_ec (TestPeerBasics::make_error (TestPeerBasics::errc::skipped)) - , m_message (m_ec.message ()) -{ -} - -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 ()) -{ -} - -PeerTest::Result::Result (std::exception const& e, String const& prefix) - : m_ec (TestPeerBasics::make_error (TestPeerBasics::errc::exceptioned)) - , m_message ((prefix == String::empty) ? e.what () - : prefix + ": " + e.what ()) -{ -} - -bool PeerTest::Result::operator== (Result const& other) const noexcept -{ - return m_ec == other.m_ec; -} - -bool PeerTest::Result::operator!= (Result const& other) const noexcept -{ - return m_ec != other.m_ec; -} - -bool PeerTest::Result::failed () const noexcept -{ - return TestPeerBasics::failure (m_ec); -} - -bool PeerTest::Result::timedout () const noexcept -{ - return m_ec == TestPeerBasics::make_error (TestPeerBasics::errc::timeout); -} - -String PeerTest::Result::message () const noexcept -{ - return m_message; -} - -bool PeerTest::Result::report (unit_test::suite& suite, - bool reportPassingTests) const -{ - bool const success = suite.expect (! failed (), - message ().toStdString()); - if (reportPassingTests && success) - suite.log << - "pass " + message().toStdString(); - return success; -} - -//------------------------------------------------------------------------------ - -PeerTest::Results::Results () - : name ("unknown") -{ -} - -bool PeerTest::Results::operator== (Results const& other) const noexcept -{ - return (client == other.client) && (server == other.server); -} - -bool PeerTest::Results::operator!= (Results const& other) const noexcept -{ - return (client != other.client) || (server != other.server); -} - -bool PeerTest::Results::report (unit_test::suite& suite, - bool beginTestCase) const -{ - if (beginTestCase) - suite.testcase << name.toStdString(); - bool success = true; - if (! client.report (suite)) - success = false; - if (! server.report (suite)) - success = false; - return success; -} - -} -} diff --git a/beast/module/asio/tests/PeerTest.h b/beast/module/asio/tests/PeerTest.h deleted file mode 100644 index 48345b14c3..0000000000 --- a/beast/module/asio/tests/PeerTest.h +++ /dev/null @@ -1,247 +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_ASIO_TESTS_PEERTEST_H_INCLUDED -#define BEAST_ASIO_TESTS_PEERTEST_H_INCLUDED - -#include - -namespace beast { -namespace asio { - -/** Performs a test of two peers defined by template parameters. */ -class PeerTest -{ -public: - enum - { - /** How long to wait before aborting a peer and reporting a timeout. - - @note Aborting synchronous logics may cause undefined behavior. - */ - defaultTimeoutSeconds = 30 - }; - - //-------------------------------------------------------------------------- - - /** Holds the test results for one peer. - */ - class Result - { - public: - /** Default constructor indicates the test was skipped. - */ - Result (); - - /** Construct from an error code. - The prefix is prepended to the error message. - */ - explicit Result (boost::system::error_code const& ec, String const& prefix = ""); - explicit Result (std::exception const& e, String const& prefix = ""); - - /** Returns true if the error codes match (message is ignored). - */ - bool operator== (Result const& other) const noexcept; - bool operator!= (Result const& other) const noexcept; - - /** Returns true if the peer failed. - */ - bool failed () const noexcept; - - /** Convenience for determining if the peer timed out. - */ - bool timedout () const noexcept; - - /** Provides a descriptive message. - This is suitable to pass to suite::fail. - */ - String message () const noexcept; - - /** Report the result to a testsuite. - A return value of true indicates success. - */ - bool report (unit_test::suite& suite, - bool reportPassingTests = false) const; - - private: - boost::system::error_code m_ec; - String m_message; - }; - - //-------------------------------------------------------------------------- - - /** Holds the results for both peers in a test. - */ - struct Results - { - String name; // A descriptive name for this test case. - Result client; - Result server; - - Results (); - - /** Determines if client and server results match. */ - bool operator== (Results const& other) const noexcept; - bool operator!= (Results const& other) const noexcept; - - /** Report the results to a suite object. - A return value of true indicates success. - @param beginTestCase `true` to call test.beginTestCase for you - */ - bool report (unit_test::suite& suite, bool beginTestCase = true) const; - }; - - //-------------------------------------------------------------------------- - - /** Test two peers and return the results. - */ - template - static Results run (ClientArg const& clientArg, ServerArg const& serverArg, - int timeoutSeconds = defaultTimeoutSeconds) - { - Results results; - - if (Process::isRunningUnderDebugger ()) - timeoutSeconds = -1; - - try - { - TestPeerType server (serverArg); - - results.name = server.name () + Details::getArgName (serverArg); - - try - { - TestPeerType client (clientArg); - - results.name << " / " + client.name () + Details::getArgName (clientArg); - - try - { - server.start (timeoutSeconds); - - try - { - client.start (timeoutSeconds); - - boost::system::error_code const ec = client.join (); - - results.client = Result (ec, client.name ()); - - try - { - boost::system::error_code const ec = server.join (); - - results.server = Result (ec, server.name ()); - } - catch (std::exception& e) - { - results.server = Result (e, server.name ()); - } - catch (...) - { - results.server = Result (TestPeerBasics::make_error ( - TestPeerBasics::errc::exceptioned), server.name ()); - } - } - catch (std::exception& e) - { - results.server = Result (e, client.name ()); - } - catch (...) - { - results.client = Result (TestPeerBasics::make_error ( - TestPeerBasics::errc::exceptioned), client.name ()); - } - } - catch (std::exception& e) - { - results.server = Result (e, server.name ()); - } - catch (...) - { - results.server = Result (TestPeerBasics::make_error ( - TestPeerBasics::errc::exceptioned), server.name ()); - } - } - catch (std::exception& e) - { - results.server = Result (e, "client"); - } - catch (...) - { - results.client = Result (TestPeerBasics::make_error ( - TestPeerBasics::errc::exceptioned), "client"); - } - } - catch (std::exception& e) - { - results.server = Result (e, "server"); - } - catch (...) - { - results.server = Result (TestPeerBasics::make_error ( - TestPeerBasics::errc::exceptioned), "server"); - } - - return results; - } - - template - static Results run (Arg const& arg, int timeoutSeconds = defaultTimeoutSeconds) - { - return run ( - arg, arg, timeoutSeconds); - } - - //-------------------------------------------------------------------------- - - template - static void report_async (unit_test::suite& suite, Arg const& arg, - int timeoutSeconds = defaultTimeoutSeconds, - bool beginTestCase = true) - { - run - (arg, timeoutSeconds).report (suite, beginTestCase); - } - - template - static - void - report (unit_test::suite& suite, Arg const& arg, - int timeoutSeconds = defaultTimeoutSeconds, bool beginTestCase = true) - { - run - (arg, timeoutSeconds).report (suite, beginTestCase); - - run - (arg, timeoutSeconds).report (suite, beginTestCase); - - run - (arg, timeoutSeconds).report (suite, beginTestCase); - - report_async
(suite, arg, timeoutSeconds, beginTestCase); - } -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeer.h b/beast/module/asio/tests/TestPeer.h deleted file mode 100644 index ae2aef2afe..0000000000 --- a/beast/module/asio/tests/TestPeer.h +++ /dev/null @@ -1,58 +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_ASIO_TESTS_TESTPEER_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEER_H_INCLUDED - -namespace beast { -namespace asio { - -/** An abstract peer for unit tests. */ -class TestPeer : public TestPeerBasics -{ -public: - enum - { - // This should be long enough to go about your business. - defaultTimeout = 10 - }; - - virtual ~TestPeer () { } - - /** Get the name of this peer. */ - virtual String name () const = 0; - - /** Start the peer. - If timeoutSeconds is 0 or less, the wait is infinite. - @param timeoutSeconds How long until the peer should be - considered timed out. - */ - virtual void start (int timeoutSeconds = defaultTimeout) = 0; - - /** Wait for the peer to finish. - - @return Any error code generated during the server operation. - */ - virtual boost::system::error_code join () = 0; -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerBasics.cpp b/beast/module/asio/tests/TestPeerBasics.cpp deleted file mode 100644 index 696953fe32..0000000000 --- a/beast/module/asio/tests/TestPeerBasics.cpp +++ /dev/null @@ -1,161 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -TestPeerBasics::Model::Model (model_t model) - : m_model (model) -{ -} - -String TestPeerBasics::Model::name () const noexcept -{ - if (m_model == async) - return "async"; - return "sync"; -} - -bool TestPeerBasics::Model::operator== (model_t model) const noexcept -{ - return m_model == model; -} - -boost::asio::ssl::stream_base::handshake_type - TestPeerBasics::to_handshake_type (PeerRole const& role) -{ - if (role == PeerRole::client) - return boost::asio::ssl::stream_base::client; - return boost::asio::ssl::stream_base::server; -} - -//------------------------------------------------------------------------------ - -boost::system::error_category const& TestPeerBasics::test_category () noexcept -{ - struct test_category_type : boost::system::error_category - { - char const* name () const noexcept - { - return "TestPeer"; - } - - std::string message (int ev) const - { - switch (ev) - { - case errc::none: return "No error"; - case errc::timeout: return "The timeout expired before the test could complete"; - case errc::unexpected: return "An unexpected test result was encountered"; - case errc::exceptioned: return "An unexpected exception was thrown"; - case errc::skipped: return "The test was skipped because of previous errors"; - default: - break; - }; - - return "An unknown error"; - } - - boost::system::error_condition default_error_condition (int ev) const noexcept - { - return boost::system::error_condition (ev, *this); - } - - bool equivalent (int ev, boost::system::error_condition const& condition) const noexcept - { - return default_error_condition (ev) == condition; - } - - bool equivalent (boost::system::error_code const& code, int ev) const noexcept - { - return *this == code.category() && code.value() == ev; - } - }; - - static test_category_type category; - - return category; -} - -boost::system::error_code TestPeerBasics::make_error (errc::errc_t ev) noexcept -{ - return boost::system::error_code (ev, test_category ()); -} - -boost::system::error_code TestPeerBasics::make_error (errc::errc_t ev, boost::system::error_code& ec) noexcept -{ - return ec = make_error (ev); -} - -bool TestPeerBasics::success (boost::system::error_code const& ec, bool eofIsOkay) noexcept -{ - if (eofIsOkay && ec == boost::asio::error::eof) - return true; - if (! ec) - return true; - breakpoint (ec); - return false; -} - -bool TestPeerBasics::failure (boost::system::error_code const& ec, bool eofIsOkay) noexcept -{ - return ! success (ec, eofIsOkay); -} - -bool TestPeerBasics::expected (bool condition, boost::system::error_code& ec) noexcept -{ - if (condition) - { - ec = boost::system::error_code (); - } - else - { - make_error (errc::unexpected, ec); - breakpoint (ec); - } - return condition; -} - -bool TestPeerBasics::unexpected (bool condition, boost::system::error_code& ec) noexcept -{ - return ! expected (condition, ec); -} - -bool TestPeerBasics::aborted (boost::system::error_code const& ec) noexcept -{ - return ec == boost::asio::error::operation_aborted; -} - -//------------------------------------------------------------------------------ - -void TestPeerBasics::breakpoint (boost::system::error_code const& ec) -{ - // Set a breakpoint here to catch a failure - std::string const& message = ec.message (); - char const* const c_str = message.c_str (); - - breakpoint (c_str); -} - -void TestPeerBasics::breakpoint (char const* const) -{ -} - -} -} diff --git a/beast/module/asio/tests/TestPeerBasics.h b/beast/module/asio/tests/TestPeerBasics.h deleted file mode 100644 index 1d7fb87eb4..0000000000 --- a/beast/module/asio/tests/TestPeerBasics.h +++ /dev/null @@ -1,114 +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_ASIO_TESTS_TESTPEERBASICS_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERBASICS_H_INCLUDED - -#include - -namespace beast { -namespace asio { - -/** Common declarations for TestPeer. - - @see TestPeer -*/ -class TestPeerBasics -{ -public: - /** Selects between synchronous or asynchronous networking i/o usage. */ - struct Model - { - enum model_t - { - sync, - async - }; - - Model (model_t model); - String name () const noexcept; - bool operator== (model_t model) const noexcept; - - private: - model_t m_model; - }; - - //-------------------------------------------------------------------------- - - /** Convert a PeerRole to boost::asio::ssl::stream_base_handshake_type */ - static boost::asio::ssl::stream_base::handshake_type to_handshake_type (PeerRole const& role); - - //-------------------------------------------------------------------------- - - // Custom error codes for distinguishing test conditions - struct errc - { - enum errc_t - { - none = 0, - timeout, // The peer join timeout expired - unexpected, // An expected condition was false - exceptioned, // An exception occurred - skipped // Test skipped due to previous errors - }; - }; - - /** Returns the category that represents TestPeer errors. - */ - static boost::system::error_category const& test_category () noexcept; - - /** Creates a test error_code from the give code value. - */ - static boost::system::error_code make_error (errc::errc_t ev) noexcept; - - /** Sets the passed error_code to a test error and returns it. - */ - static boost::system::error_code make_error (errc::errc_t ev, - boost::system::error_code& ec) noexcept; - - /** Returns true if the error code indicates success. - */ - static bool success (boost::system::error_code const& ec, bool eofIsOkay = false) noexcept; - - /** Returns false if the error code indicates failure. - */ - static bool failure (boost::system::error_code const& ec, bool eofIsOkay = false) noexcept; - - /** Set the error based on a failed condition and return the success. - */ - static bool expected (bool condition, boost::system::error_code& ec) noexcept; - - /** Set the error based on a passed condition and return the success. - */ - static bool unexpected (bool condition, boost::system::error_code& ec) noexcept; - - /** Returns true if the error condition indicates an aborted I/O. */ - static bool aborted (boost::system::error_code const& ec) noexcept; - - /** Provides a place to set a breakpoint to catch a failed condition. */ - static void breakpoint (boost::system::error_code const& ec); - - /** Forces the variable to exist in the debugger. */ - static void breakpoint (char const* const message); -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerDetails.h b/beast/module/asio/tests/TestPeerDetails.h deleted file mode 100644 index 7a4a79fe2e..0000000000 --- a/beast/module/asio/tests/TestPeerDetails.h +++ /dev/null @@ -1,52 +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_ASIO_TESTS_TESTPEERDETAILS_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERDETAILS_H_INCLUDED - -#include - -namespace beast { -namespace asio { - -/** Base class of all detail objects. */ -class TestPeerDetails -{ -public: - virtual ~TestPeerDetails () { } - - virtual String name () const = 0; - - virtual abstract_socket& get_socket () = 0; - - virtual abstract_socket& get_acceptor () = 0; - - boost::asio::io_service& get_io_service () - { - return m_io_service; - } - -private: - boost::asio::io_service m_io_service; -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerDetailsTcp.h b/beast/module/asio/tests/TestPeerDetailsTcp.h deleted file mode 100644 index b72b939159..0000000000 --- a/beast/module/asio/tests/TestPeerDetailsTcp.h +++ /dev/null @@ -1,115 +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_ASIO_TESTS_TESTPEERDETAILSTCP_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERDETAILSTCP_H_INCLUDED - -#include - -namespace beast { -namespace asio { - -/** Some predefined Detail classes for TestPeer */ -struct TcpDetails : public TestPeerDetails -{ -protected: - typedef boost::asio::ip::tcp protocol_type; - typedef protocol_type::socket socket_type; - typedef protocol_type::acceptor acceptor_type; - typedef protocol_type::endpoint endpoint_type; - typedef protocol_type::resolver resolver_type; - -public: - typedef protocol_type arg_type; - typedef socket_type native_socket_type; - typedef acceptor_type native_acceptor_type; - - explicit TcpDetails (arg_type protocol) - : m_protocol (protocol) - , m_socket (get_io_service ()) - , m_acceptor (get_io_service ()) - , m_socket_wrapper (m_socket) - , m_acceptor_wrapper (m_acceptor) - { - } - - static String getArgName (arg_type arg) - { - if (arg == protocol_type::v4 ()) - return ".tcpv4"; - else if (arg == protocol_type::v6 ()) - return ".tcpv6"; - return ".tcp?"; - } - - String name () const - { - return getArgName (m_protocol); - } - - abstract_socket& get_socket () - { - return m_socket_wrapper; - } - - abstract_socket& get_acceptor () - { - return m_acceptor_wrapper; - } - - socket_type& get_native_socket () - { - return m_socket; - } - - acceptor_type& get_native_acceptor () - { - return m_acceptor; - } - - endpoint_type get_endpoint (PeerRole role) - { - if (m_protocol == protocol_type::v4 ()) - { - if (role == PeerRole::server) - return endpoint_type (m_protocol, 1053); - else - return endpoint_type (boost::asio::ip::address_v4::loopback (), 1053); - } - else - { - if (role == PeerRole::server) - return endpoint_type (m_protocol, 1052); - else - return endpoint_type (boost::asio::ip::address_v6 ().from_string ("::1"), 1052); - } - } - -protected: - protocol_type m_protocol; - socket_type m_socket; - acceptor_type m_acceptor; - socket_wrapper m_socket_wrapper; - socket_wrapper m_acceptor_wrapper; -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerLogic.cpp b/beast/module/asio/tests/TestPeerLogic.cpp deleted file mode 100644 index c3887587c9..0000000000 --- a/beast/module/asio/tests/TestPeerLogic.cpp +++ /dev/null @@ -1,69 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -TestPeerLogic::TestPeerLogic (abstract_socket& socket) - : m_socket (&socket) -{ -} - -TestPeerLogic::error_code& TestPeerLogic::error () noexcept -{ - return m_ec; -} - -TestPeerLogic::error_code const& TestPeerLogic::error () const noexcept -{ - return m_ec; -} - -TestPeerLogic::error_code const& TestPeerLogic::error (error_code const& ec) noexcept -{ - return m_ec = ec; -} - -abstract_socket& TestPeerLogic::socket () noexcept -{ - return *m_socket; -} - -void TestPeerLogic::on_connect () -{ - pure_virtual (); -} - -void TestPeerLogic::on_connect_async (error_code const&) -{ - pure_virtual (); -} - -void TestPeerLogic::finished () -{ - pure_virtual (); -} - -void TestPeerLogic::pure_virtual () -{ - fatal_error ("A TestPeerLogic function was called incorrectly"); -} - -} -} diff --git a/beast/module/asio/tests/TestPeerLogic.h b/beast/module/asio/tests/TestPeerLogic.h deleted file mode 100644 index bb5281f5d8..0000000000 --- a/beast/module/asio/tests/TestPeerLogic.h +++ /dev/null @@ -1,62 +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_ASIO_TESTS_TESTPEERLOGIC_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERLOGIC_H_INCLUDED - -namespace beast { -namespace asio { - -/** Interface for implementing the logic part of a peer test. */ -class TestPeerLogic : public TestPeerBasics -{ -public: - typedef boost::system::error_code error_code; - - explicit TestPeerLogic (abstract_socket& socket); - - error_code& error () noexcept; - error_code const& error () const noexcept; - error_code const& error (error_code const& ec) noexcept; // assigns to m_ec - - abstract_socket& socket () noexcept; - - virtual PeerRole get_role () const noexcept = 0; - - virtual Model get_model () const noexcept = 0; - - virtual void on_connect (); - - virtual void on_connect_async (error_code const&); - - // asynchronous logic classes - // must call this when they are done - virtual void finished (); - - static void pure_virtual (); - -private: - error_code m_ec; - abstract_socket* m_socket; -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerLogicAsyncClient.cpp b/beast/module/asio/tests/TestPeerLogicAsyncClient.cpp deleted file mode 100644 index 3dfc4ef928..0000000000 --- a/beast/module/asio/tests/TestPeerLogicAsyncClient.cpp +++ /dev/null @@ -1,164 +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. -*/ -//============================================================================== - -#include - -namespace beast { -namespace asio { - -TestPeerLogicAsyncClient::TestPeerLogicAsyncClient (abstract_socket& socket) - : TestPeerLogic (socket) -{ -} - -PeerRole TestPeerLogicAsyncClient::get_role () const noexcept -{ - return PeerRole::client; -} - -TestPeerBasics::Model TestPeerLogicAsyncClient::get_model () const noexcept -{ - return Model::async; -} - -void TestPeerLogicAsyncClient::on_connect_async (error_code const& ec) -{ - if (aborted (ec) || failure (error (ec))) - return finished (); - - if (socket ().needs_handshake ()) - { - socket ().async_handshake (abstract_socket::client, - std::bind (&TestPeerLogicAsyncClient::on_handshake, this, - beast::asio::placeholders::error)); - } - else - { - on_handshake (ec); - } -} - -void TestPeerLogicAsyncClient::on_handshake (error_code const& ec) -{ - if (aborted (ec) || failure (error (ec))) - return finished (); - - boost::asio::async_write (socket (), boost::asio::buffer ("hello", 5), - std::bind (&TestPeerLogicAsyncClient::on_write, this, - beast::asio::placeholders::error, - beast::asio::placeholders::bytes_transferred)); -} - -void TestPeerLogicAsyncClient::on_write (error_code const& ec, std::size_t bytes_transferred) -{ - if (aborted (ec) || failure (error (ec))) - return finished (); - - if (unexpected (bytes_transferred == 5, error ())) - return finished (); - - boost::asio::async_read_until (socket (), m_buf, std::string ("goodbye"), - std::bind (&TestPeerLogicAsyncClient::on_read, this, - beast::asio::placeholders::error, beast::asio::placeholders::bytes_transferred)); -} - -void TestPeerLogicAsyncClient::on_read (error_code const& ec, std::size_t bytes_transferred) -{ - if (aborted (ec) || failure (error (ec))) - return finished (); - - if (unexpected (bytes_transferred == 7, error ())) - return finished (); - - // should check the data here? - m_buf.consume (bytes_transferred); - - // Fire up a 1 byte read, to wait for the server to - // shut down its end of the connection. - boost::asio::async_read (socket (), m_buf.prepare (1), - std::bind (&TestPeerLogicAsyncClient::on_read_final, this, - beast::asio::placeholders::error, beast::asio::placeholders::bytes_transferred)); -} - -void TestPeerLogicAsyncClient::on_read_final (error_code const& ec, std::size_t) -{ - if (aborted (ec)) - return finished (); - - // An eof is the normal case. The server should have closed shop. - // - if (ec == boost::asio::error::eof) - { - if (socket ().needs_handshake ()) - { - socket ().async_shutdown (std::bind (&TestPeerLogicAsyncClient::on_shutdown, this, - beast::asio::placeholders::error)); - } - else - { - // on_shutdown will call finished () - error_code ec; - on_shutdown (socket ().shutdown (abstract_socket::shutdown_send, ec)); - } - } - else - { - // If we don't get eof, then there should be some other - // error in there. We don't expect the server to send more bytes! - // - // This statement will do the following: - // - // error (ec) save ec into our error state - // success () return true if ec represents success - // unexpected () changes error() to 'unexpected' result if - // success() returned true - // - unexpected (success (error (ec)), error ()); - - return finished (); - } -} - -void TestPeerLogicAsyncClient::on_shutdown (error_code const& ec) -{ - if (! aborted (ec)) - { - if (success (error (ec), true)) - { - if (socket ().needs_handshake ()) - { - socket ().shutdown (abstract_socket::shutdown_send, error ()); - } - - if (! error ()) - { - if (success (socket ().close (error ()))) - { - // doing nothing here is intended, - // as the calls to success() may set error() - } - } - } - } - - finished (); -} - -} -} diff --git a/beast/module/asio/tests/TestPeerLogicAsyncClient.h b/beast/module/asio/tests/TestPeerLogicAsyncClient.h deleted file mode 100644 index bf1a65c5db..0000000000 --- a/beast/module/asio/tests/TestPeerLogicAsyncClient.h +++ /dev/null @@ -1,45 +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_ASIO_TESTS_TESTPEERLOGICASYNCCLIENT_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERLOGICASYNCCLIENT_H_INCLUDED - -namespace beast { -namespace asio { - -class TestPeerLogicAsyncClient : public TestPeerLogic -{ -public: - explicit TestPeerLogicAsyncClient (abstract_socket& socket); - PeerRole get_role () const noexcept; - Model get_model () const noexcept; - void on_connect_async (error_code const& ec); - void on_handshake (error_code const& ec); - void on_write (error_code const& ec, std::size_t bytes_transferred); - void on_read (error_code const& ec, std::size_t bytes_transferred); - void on_read_final (error_code const& ec, std::size_t); - void on_shutdown (error_code const& ec); -private: - boost::asio::streambuf m_buf; -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerLogicAsyncServer.cpp b/beast/module/asio/tests/TestPeerLogicAsyncServer.cpp deleted file mode 100644 index da3d51fe00..0000000000 --- a/beast/module/asio/tests/TestPeerLogicAsyncServer.cpp +++ /dev/null @@ -1,126 +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. -*/ -//============================================================================== - -#include - -namespace beast { -namespace asio { - -TestPeerLogicAsyncServer::TestPeerLogicAsyncServer (abstract_socket& socket) - : TestPeerLogic (socket) -{ -} - -PeerRole TestPeerLogicAsyncServer::get_role () const noexcept -{ - return PeerRole::server; -} - -TestPeerBasics::Model TestPeerLogicAsyncServer::get_model () const noexcept -{ - return Model::async; -} - -void TestPeerLogicAsyncServer::on_connect_async (error_code const& ec) -{ - if (aborted (ec) || failure (error (ec))) - return finished (); - - if (socket ().needs_handshake ()) - { - socket ().async_handshake (abstract_socket::server, - std::bind (&TestPeerLogicAsyncServer::on_handshake, this, - beast::asio::placeholders::error)); - } - else - { - on_handshake (ec); - } -} - -void TestPeerLogicAsyncServer::on_handshake (error_code const& ec) -{ - if (aborted (ec) || failure (error (ec))) - return finished (); - - boost::asio::async_read_until (socket (), m_buf, std::string ("hello"), - std::bind (&TestPeerLogicAsyncServer::on_read, this, - beast::asio::placeholders::error, beast::asio::placeholders::bytes_transferred)); -} - -void TestPeerLogicAsyncServer::on_read (error_code const& ec, std::size_t bytes_transferred) -{ - if (aborted (ec) || failure (error (ec))) - return finished (); - - if (unexpected (bytes_transferred == 5, error ())) - return finished (); - - boost::asio::async_write (socket (), boost::asio::buffer ("goodbye", 7), - std::bind (&TestPeerLogicAsyncServer::on_write, this, - beast::asio::placeholders::error, beast::asio::placeholders::bytes_transferred)); -} - -void TestPeerLogicAsyncServer::on_write (error_code const& ec, std::size_t bytes_transferred) -{ - if (aborted (ec) || failure (error (ec))) - return finished (); - - if (unexpected (bytes_transferred == 7, error ())) - return finished (); - - if (socket ().needs_handshake ()) - { - socket ().async_shutdown (std::bind (&TestPeerLogicAsyncServer::on_shutdown, this, - beast::asio::placeholders::error)); - } - else - { - // on_shutdown will call finished () - // we need another instance of ec so we can call on_shutdown() - error_code ec; - on_shutdown (socket ().shutdown (abstract_socket::shutdown_receive, ec)); - } -} - -void TestPeerLogicAsyncServer::on_shutdown (error_code const& ec) -{ - if (! aborted (ec)) - { - if (success (error (ec), true)) - { - if (socket ().needs_handshake ()) - { - socket ().shutdown (abstract_socket::shutdown_receive, error ()); - } - - if (success (socket ().close (error ()))) - { - // doing nothing here is intended, - // as the calls to success() may set error() - } - } - } - - finished (); -} - -} -} - diff --git a/beast/module/asio/tests/TestPeerLogicAsyncServer.h b/beast/module/asio/tests/TestPeerLogicAsyncServer.h deleted file mode 100644 index dd47170ce0..0000000000 --- a/beast/module/asio/tests/TestPeerLogicAsyncServer.h +++ /dev/null @@ -1,44 +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_ASIO_TESTS_TESTPEERLOGICASYNCSERVER_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERLOGICASYNCSERVER_H_INCLUDED - -namespace beast { -namespace asio { - -class TestPeerLogicAsyncServer : public TestPeerLogic -{ -public: - explicit TestPeerLogicAsyncServer (abstract_socket& socket); - PeerRole get_role () const noexcept; - Model get_model () const noexcept; - void on_connect_async (error_code const& ec); - void on_handshake (error_code const& ec); - void on_read (error_code const& ec, std::size_t bytes_transferred); - void on_write (error_code const& ec, std::size_t bytes_transferred); - void on_shutdown (error_code const& ec); -private: - boost::asio::streambuf m_buf; -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerLogicProxyClient.cpp b/beast/module/asio/tests/TestPeerLogicProxyClient.cpp deleted file mode 100644 index 71e6b5ffa7..0000000000 --- a/beast/module/asio/tests/TestPeerLogicProxyClient.cpp +++ /dev/null @@ -1,42 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -TestPeerLogicProxyClient::TestPeerLogicProxyClient (abstract_socket& socket) - : TestPeerLogicSyncClient (socket) -{ -} - -void TestPeerLogicProxyClient::on_pre_handshake () -{ - //ProxyHandshakeParser h; - - static std::string line ( - "PROXY TCP4 255.255.255.255 255.255.255.255 65535 65535\r\n" - // 56 chars - ); - - boost::asio::write (socket (), boost::asio::buffer (line), error ()); -} - -} -} - diff --git a/beast/module/asio/tests/TestPeerLogicProxyClient.h b/beast/module/asio/tests/TestPeerLogicProxyClient.h deleted file mode 100644 index 7efaf31755..0000000000 --- a/beast/module/asio/tests/TestPeerLogicProxyClient.h +++ /dev/null @@ -1,37 +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_ASIO_TESTS_TESTPEERLOGICPROXYCLIENT_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERLOGICPROXYCLIENT_H_INCLUDED - -namespace beast { -namespace asio { - -/** A synchronous client logic that sends a PROXY protocol pre-handshake. */ -class TestPeerLogicProxyClient : public TestPeerLogicSyncClient -{ -public: - explicit TestPeerLogicProxyClient (abstract_socket& socket); - void on_pre_handshake (); -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerLogicSyncClient.cpp b/beast/module/asio/tests/TestPeerLogicSyncClient.cpp deleted file mode 100644 index 0dcf0ff242..0000000000 --- a/beast/module/asio/tests/TestPeerLogicSyncClient.cpp +++ /dev/null @@ -1,115 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -TestPeerLogicSyncClient::TestPeerLogicSyncClient (abstract_socket& socket) - : TestPeerLogic (socket) -{ -} - -PeerRole TestPeerLogicSyncClient::get_role () const noexcept -{ - return PeerRole::client; -} - -TestPeerBasics::Model TestPeerLogicSyncClient::get_model () const noexcept -{ - return Model::sync; -} - -void TestPeerLogicSyncClient::on_connect () -{ - { - // pre-handshake hook is optional - on_pre_handshake (); - if (failure (error ())) - return ; - } - - if (socket ().needs_handshake ()) - { - if (failure (socket ().handshake (to_handshake_type (get_role ()), error ()))) - return; - } - - { - std::size_t const amount = boost::asio::write ( - socket (), boost::asio::buffer ("hello", 5), error ()); - - if (failure (error ())) - return; - - if (unexpected (amount == 5, error ())) - return; - } - - { - char data [7]; - - size_t const amount = boost::asio::read ( - socket (), boost::asio::buffer (data, 7), error ()); - - if (failure (error ())) - return; - - if (unexpected (amount == 7, error ())) - return; - - if (unexpected (memcmp (&data, "goodbye", 7) == 0, error ())) - return; - } - - // Wait for 1 byte which should never come. Instead, - // the server should close its end and we will get eof - { - char data [1]; - boost::asio::read (socket (), boost::asio::buffer (data, 1), error ()); - - if (error () == boost::asio::error::eof) - { - error () = error_code (); - } - else if (unexpected (failure (error ()), error ())) - { - return; - } - } - - if (socket ().needs_handshake ()) - { - if (failure (socket ().shutdown (error ()), true)) - return; - error () = error_code (); - } - - if (failure (socket ().shutdown (abstract_socket::shutdown_send, error ()))) - return; - - if (failure (socket ().close (error ()))) - return; -} - -void TestPeerLogicSyncClient::on_pre_handshake () -{ -} -} - -} diff --git a/beast/module/asio/tests/TestPeerLogicSyncClient.h b/beast/module/asio/tests/TestPeerLogicSyncClient.h deleted file mode 100644 index b59c0505c6..0000000000 --- a/beast/module/asio/tests/TestPeerLogicSyncClient.h +++ /dev/null @@ -1,39 +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_ASIO_TESTS_TESTPEERLOGICSYNCCLIENT_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERLOGICSYNCCLIENT_H_INCLUDED - -namespace beast { -namespace asio { - -class TestPeerLogicSyncClient : public TestPeerLogic -{ -public: - explicit TestPeerLogicSyncClient (abstract_socket& socket); - PeerRole get_role () const noexcept; - Model get_model () const noexcept; - void on_connect (); - virtual void on_pre_handshake (); -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerLogicSyncServer.cpp b/beast/module/asio/tests/TestPeerLogicSyncServer.cpp deleted file mode 100644 index 6fc542d640..0000000000 --- a/beast/module/asio/tests/TestPeerLogicSyncServer.cpp +++ /dev/null @@ -1,86 +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. -*/ -//============================================================================== - -namespace beast { -namespace asio { - -TestPeerLogicSyncServer::TestPeerLogicSyncServer (abstract_socket& socket) - : TestPeerLogic (socket) -{ -} - -PeerRole TestPeerLogicSyncServer::get_role () const noexcept -{ - return PeerRole::server; -} - -TestPeerBasics::Model TestPeerLogicSyncServer::get_model () const noexcept -{ - return Model::sync; -} - -void TestPeerLogicSyncServer::on_connect () -{ - if (socket ().needs_handshake ()) - { - if (failure (socket ().handshake (to_handshake_type (get_role ()), error ()))) - return; - } - - { - boost::asio::streambuf buf (5); - std::size_t const amount = boost::asio::read_until ( - socket (), buf, "hello", error ()); - - if (failure (error ())) - return; - - if (unexpected (amount == 5, error ())) - return; - - if (unexpected (buf.size () == 5, error ())) - return; - } - - { - std::size_t const amount = boost::asio::write ( - socket (), boost::asio::buffer ("goodbye", 7), error ()); - - if (failure (error ())) - return; - - if (unexpected (amount == 7, error ())) - return; - } - - if (socket ().needs_handshake ()) - { - if (failure (socket ().shutdown (error ()), true)) - return; - } - - if (failure (socket ().shutdown (abstract_socket::shutdown_send, error ()))) - return; - - if (failure (socket ().close (error ()))) - return; -} - -} -} diff --git a/beast/module/asio/tests/TestPeerLogicSyncServer.h b/beast/module/asio/tests/TestPeerLogicSyncServer.h deleted file mode 100644 index ce8cd76a2d..0000000000 --- a/beast/module/asio/tests/TestPeerLogicSyncServer.h +++ /dev/null @@ -1,38 +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_ASIO_TESTS_TESTPEERLOGICSYNCSERVER_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERLOGICSYNCSERVER_H_INCLUDED - -namespace beast { -namespace asio { - -class TestPeerLogicSyncServer : public TestPeerLogic -{ -public: - explicit TestPeerLogicSyncServer (abstract_socket& socket); - PeerRole get_role () const noexcept; - Model get_model () const noexcept; - void on_connect (); -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerType.h b/beast/module/asio/tests/TestPeerType.h deleted file mode 100644 index 47b1d323a0..0000000000 --- a/beast/module/asio/tests/TestPeerType.h +++ /dev/null @@ -1,404 +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_ASIO_TESTS_TESTPEERTYPE_H_INCLUDED -#define BEAST_ASIO_TESTS_TESTPEERTYPE_H_INCLUDED - -#include - -namespace beast { -namespace asio { - -template -class TestPeerType - : public Details - , public Logic - , public TestPeer - , public Thread -{ -protected: - // TestPeerDetails - using Details::get_socket; - using Details::get_acceptor; - using Details::get_io_service; - - // Details - typedef typename Details::protocol_type protocol_type; - typedef typename Details::socket_type socket_type; - typedef typename Details::acceptor_type acceptor_type; - typedef typename Details::endpoint_type endpoint_type; - typedef typename Details::resolver_type resolver_type; - - using Details::get_native_socket; - using Details::get_native_acceptor; - using Details::get_endpoint; - - // TestPeerLogic - typedef typename Logic::error_code error_code; - using Logic::error; - using Logic::socket; - using Logic::get_role; - using Logic::get_model; - using Logic::on_connect; - using Logic::on_connect_async; - using Logic::pure_virtual; - - typedef TestPeerType This; - -public: - // Details - typedef typename Details::arg_type arg_type; - typedef typename Details::native_socket_type native_socket_type; - typedef typename Details::native_acceptor_type native_acceptor_type; - - TestPeerType (arg_type const& arg) - : Details (arg) - , Logic (get_socket ()) - , Thread (name ()) - , m_timer (get_io_service ()) - , m_timer_set (false) - , m_timed_out (false) - { - } - - ~TestPeerType () - { - } - - String name () const - { - return get_model ().name () + "_" + get_role ().name (); - } - - bool is_async () const noexcept - { - return get_model () == Model::async; - } - - void start (int timeoutSeconds) - { - if (is_async ()) - { - if (timeoutSeconds > 0) - { - m_timer.expires_from_now ( - boost::posix_time::seconds (timeoutSeconds)); - - m_timer.async_wait (std::bind (&This::on_deadline, - this, beast::asio::placeholders::error)); - - m_timer_set = true; - } - else - { - // Don't set the timer, so infinite wait. - } - } - else - { - // Save the value for when join() is called later. - // - m_timeoutSeconds = timeoutSeconds; - } - - startThread (); - - // For server roles block until the thread is litening. - // - if (get_role () == PeerRole::server) - m_listening.wait (); - } - - error_code join () - { - if (is_async ()) - { - // If the timer expired, then all our i/o should be - // aborted and the thread will exit. So we will wait - // for the thread for an infinite amount of time to - // prevent undefined behavior. If an asynchronous logic - // fails to end when the deadline timer expires, it - // means there's a bug in the logic code. - // - m_join.wait (); - - // The wait was satisfied but now the thread is still on - // it's way out of the thread function, so block until - // we know its done. - // - stopThread (); - - // If we timed out then always report the custom error - if (m_timed_out) - return error (make_error (errc::timeout)); - } - else - { - if (m_timeoutSeconds > 0) - { - // Wait for the thread to finish - // - if (! m_join.wait (m_timeoutSeconds * 1000)) - { - // Uh oh, we timed out! This is bad. - // The synchronous model requires that the thread - // be forcibly killed, which can result in undefined - // behavior. It's best not to perform tests with - // synchronous Logic objects that are supposed to time out. - - // Force the thread to be killed, without waiting. - stopThread (0); - - error () = make_error (errc::timeout); - } - else - { - stopThread (); - } - } - else - { - // They requested an infinite wait. - // - m_join.wait (); - - stopThread (); - } - } - - return error (); - } - - //-------------------------------------------------------------------------- - - void run () - { - if (is_async ()) - { - if (get_role () == PeerRole::server) - { - run_async_server (); - } - else if (get_role () == PeerRole::client) - { - run_async_client (); - } - else - { - error () = make_error (errc::unexpected); - } - } - else if (get_model () == Model::sync) - { - if (get_role () == PeerRole::server) - { - run_sync_server (); - } - else if (get_role () == PeerRole::client) - { - run_sync_client (); - } - else - { - error () = make_error (errc::unexpected); - } - } - else - { - error () = make_error (errc::unexpected); - } - - get_io_service ().run (); - } - - //-------------------------------------------------------------------------- - - void run_sync_server () - { - do_listen (); - - if (failure (error ())) - return finished (); - - if (failure (get_acceptor ().accept (get_socket (), error ()))) - return finished (); - - if (failure (get_acceptor ().close (error ()))) - return finished (); - - this->on_connect (); - - finished (); - } - - //-------------------------------------------------------------------------- - - void on_accept (error_code const& ec) - { - if (failure (ec)) - return finished (); - - // Close the acceptor down so we don't block the io_service forever - // - // VFALCO NOTE what difference between cancel and close? -#if 0 - if (failure (get_acceptor ().close (error ()))) - return finished (); -#endif - - this->on_connect_async (ec); - } - - void run_async_server () - { - do_listen (); - - if (failure (error ())) - return finished (); - - get_acceptor ().async_accept (get_socket (), std::bind ( - &This::on_accept, this, beast::asio::placeholders::error)); - } - - //-------------------------------------------------------------------------- - - void run_sync_client () - { - if (failure (get_native_socket ().connect (get_endpoint (get_role ()), error ()))) - return finished (); - - this->on_connect (); - - finished (); - } - - void run_async_client () - { - get_native_socket ().async_connect (get_endpoint (get_role ()), - std::bind (&Logic::on_connect_async, this, - beast::asio::placeholders::error)); - } - - //-------------------------------------------------------------------------- - - void do_listen () - { - if (failure (get_native_acceptor ().open ( - get_endpoint (get_role ()).protocol (), error ()))) - return; - - // VFALCO TODO Figure out how to not hard code boost::asio::socket_base - if (failure (get_native_acceptor ().set_option ( - boost::asio::socket_base::reuse_address (true), error ()))) - return; - - if (failure (get_native_acceptor ().bind (get_endpoint (get_role ()), error ()))) - return; - - // VFALCO TODO Figure out how to not hard code boost::asio::socket_base - if (failure (get_native_acceptor ().listen ( - boost::asio::socket_base::max_connections, error ()))) - return; - - m_listening.signal (); - } - - void on_deadline (error_code const& ec) - { - m_timer_set = false; - - if (ec != boost::asio::error::operation_aborted) - { - // We expect that ec represents no error, since the - // timer expired and the operation wasn't aborted. - // - // If by some chance there is an error in ec we will - // report that as an unexpected test condition instead - // of a timeout. - // - if (expected (! ec, error ())) - m_timed_out = true; - } - else - { - // The timer was canceled because the Logic - // called finished(), so we do nothing here. - } - - finished (); - } - - void finished () - { - // If the server errors out it will come through - // here so signal the listening event and unblock - // the main thread. - // - if (get_role () == PeerRole::server) - m_listening.signal (); - - if (m_timer_set) - { - error_code ec; - std::size_t const amount = m_timer.cancel (ec); - - // The Logic should not have any I/O pending when - // it calls finished, so amount should be zero. - // - unexpected (amount == 0, ec); - } - - // The logic should close the socket at the end of - // its operations, unless it encounters an error. - // Therefore, we will clean everything up and squelch - // any errors, so that io_service::run() will return. - // - { - error_code ec; - this->get_socket ().close (ec); - } - - // The acceptor will not have closed if the client - // never established the connection, so do it here. - { - error_code ec; - this->get_acceptor ().close (ec); - } - - // Wake up the thread blocked on join() - m_join.signal (); - } - -private: - WaitableEvent m_listening; - WaitableEvent m_join; - - // for async peers - boost::asio::deadline_timer m_timer; - bool m_timer_set; - bool m_timed_out; - - // for sync peers - int m_timeoutSeconds; -}; - -} -} - -#endif diff --git a/beast/module/asio/tests/TestPeerUnitTests.cpp b/beast/module/asio/tests/TestPeerUnitTests.cpp deleted file mode 100644 index 6c673efb3d..0000000000 --- a/beast/module/asio/tests/TestPeerUnitTests.cpp +++ /dev/null @@ -1,54 +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. -*/ -//============================================================================== - -#include - -namespace beast { -namespace asio { - -/** Test suite for the TestPeer family of objects. */ -class TestPeer_test : public unit_test::suite -{ -public: - - template - void testDetails (Arg const& arg = Arg ()) - { - PeerTest::report
(*this, arg, timeoutSeconds); - } - - void run () - { - typedef boost::asio::ip::tcp protocol; - testDetails (protocol::v4 ()); - testDetails (protocol::v6 ()); - } - - //-------------------------------------------------------------------------- - - enum - { - timeoutSeconds = 10 - }; -}; - -BEAST_DEFINE_TESTSUITE(TestPeer,beast_asio,beast); - -} -} diff --git a/beast/module/core/diagnostic/FatalError.cpp b/beast/module/core/diagnostic/FatalError.cpp index 539a454994..90cd601ef1 100644 --- a/beast/module/core/diagnostic/FatalError.cpp +++ b/beast/module/core/diagnostic/FatalError.cpp @@ -17,6 +17,7 @@ */ //============================================================================== +#include #include namespace beast { diff --git a/beast/module/core/diagnostic/FatalError.h b/beast/module/core/diagnostic/FatalError.h index 5adb21a4fd..0a482dedec 100644 --- a/beast/module/core/diagnostic/FatalError.h +++ b/beast/module/core/diagnostic/FatalError.h @@ -20,6 +20,8 @@ #ifndef BEAST_CORE_FATALERROR_H_INCLUDED #define BEAST_CORE_FATALERROR_H_INCLUDED +#include + namespace beast { @@ -39,7 +41,7 @@ class FatalError public: struct Reporter { - virtual ~Reporter () { } + virtual ~Reporter() = default; /** Called when a fatal error is raised. diff --git a/beast/net/DynamicBuffer.h b/beast/net/DynamicBuffer.h index ef1c3cffea..04bcb8f288 100644 --- a/beast/net/DynamicBuffer.h +++ b/beast/net/DynamicBuffer.h @@ -60,7 +60,8 @@ public: ConstBufferType (void const* buffer, size_type bytes); */ template - std::vector data () const + std::vector + data () const { std::vector buffers; buffers.reserve (m_buffers.size()); @@ -81,7 +82,8 @@ public: MutableBufferType (void* buffer, size_type bytes); */ template - std::vector prepare (size_type amount) + std::vector + prepare (size_type amount) { std::vector buffers; buffers.reserve (m_buffers.size());