diff --git a/Jamroot b/Jamroot index c7b17d37c..1f8631154 100644 --- a/Jamroot +++ b/Jamroot @@ -53,14 +53,15 @@ project beast /boost/system//boost_system /boost/filesystem//boost_filesystem /boost/program_options//boost_program_options -# ssl -# crypto +# ssl +# crypto BOOST_ALL_NO_LIB=1 + BOOST_SYSTEM_NO_DEPRECATED=1 multi static shared - gcc:-std=c++14 - clang:-std=c++14 + gcc:-std=c++11 + clang:-std=c++11 LINUX:_XOPEN_SOURCE=600 LINUX:_GNU_SOURCE=1 SOLARIS:_XOPEN_SOURCE=500 diff --git a/examples/file_body.h b/examples/file_body.h index e46cff9ed..763c5a436 100644 --- a/examples/file_body.h +++ b/examples/file_body.h @@ -69,7 +69,7 @@ struct file_body size_ = boost::filesystem::file_size(path_); } - auto + std::size_t content_length() const { return size_; diff --git a/examples/http_async_server.h b/examples/http_async_server.h index e3ace8e9d..5438ab6e6 100644 --- a/examples/http_async_server.h +++ b/examples/http_async_server.h @@ -96,15 +96,12 @@ private: explicit peer(socket_type&& sock, std::string const& root) - : id_([] - { - static int n = 0; - return ++n; - }()) - , stream_(std::move(sock)) + : stream_(std::move(sock)) , strand_(stream_.get_io_service()) , root_(root) { + static int n = 0; + id_ = ++n; } void run() diff --git a/examples/http_stream.h b/examples/http_stream.h index d49bbac5a..cb3bdb6b6 100644 --- a/examples/http_stream.h +++ b/examples/http_stream.h @@ -21,6 +21,7 @@ #define BEAST_HTTP_STREAM_H_INCLUDED #include +#include #include #include #include @@ -94,7 +95,7 @@ class stream : public detail::stream_base public: /// The type of the next layer. using next_layer_type = - std::remove_reference_t; + typename std::remove_reference::type; /// The type of the lowest layer. using lowest_layer_type = @@ -335,7 +336,8 @@ public: #if GENERATING_DOCS void_or_deduced #else - auto + typename async_completion< + ReadHandler, void(error_code)>::result_type #endif async_read(message& msg, ReadHandler&& handler); @@ -429,7 +431,8 @@ public: #if GENERATING_DOCS void_or_deduced #else - auto + typename async_completion< + WriteHandler, void(error_code)>::result_type #endif async_write(message const& msg, WriteHandler&& handler); @@ -467,7 +470,8 @@ public: #if GENERATING_DOCS void_or_deduced #else - auto + typename async_completion< + WriteHandler, void(error_code)>::result_type #endif async_write(message&& msg, WriteHandler&& handler); diff --git a/examples/http_stream.ipp b/examples/http_stream.ipp index fa5fd7ad7..b026651e8 100644 --- a/examples/http_stream.ipp +++ b/examples/http_stream.ipp @@ -20,7 +20,6 @@ #ifndef BEAST_HTTP_STREAM_IPP_INCLUDED #define BEAST_HTTP_STREAM_IPP_INCLUDED -#include #include #include #include @@ -78,7 +77,7 @@ public: void operator()(error_code const& ec, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, read_op* op) { return boost_asio_handler_alloc_helpers:: @@ -86,7 +85,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, read_op* op) { return boost_asio_handler_alloc_helpers:: @@ -94,14 +93,14 @@ public: } friend - auto asio_handler_is_continuation(read_op* op) + bool asio_handler_is_continuation(read_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, read_op* op) + void asio_handler_invoke(Function&& f, read_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); @@ -198,7 +197,7 @@ public: void operator()(error_code const& ec, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, write_op* op) { return boost_asio_handler_alloc_helpers:: @@ -206,7 +205,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, write_op* op) { return boost_asio_handler_alloc_helpers:: @@ -214,14 +213,14 @@ public: } friend - auto asio_handler_is_continuation(write_op* op) + bool asio_handler_is_continuation(write_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, write_op* op) + void asio_handler_invoke(Function&& f, write_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); @@ -319,7 +318,9 @@ template:: async_read(message& msg, - ReadHandler&& handler) + ReadHandler&& handler) -> + typename async_completion< + ReadHandler, void(error_code)>::result_type { async_completion< ReadHandler, void(error_code) @@ -346,7 +347,9 @@ template:: async_write(message const& msg, - WriteHandler&& handler) + WriteHandler&& handler) -> + typename async_completion< + WriteHandler, void(error_code)>::result_type { async_completion< WriteHandler, void(error_code)> completion(handler); @@ -375,7 +378,9 @@ template:: async_write(message&& msg, - WriteHandler&& handler) + WriteHandler&& handler) -> + typename async_completion< + WriteHandler, void(error_code)>::result_type { async_completion< WriteHandler, void(error_code)> completion(handler); diff --git a/examples/http_sync_server.h b/examples/http_sync_server.h index db72729da..df6e42395 100644 --- a/examples/http_sync_server.h +++ b/examples/http_sync_server.h @@ -94,6 +94,28 @@ public: } } + struct lambda + { + int id; + http_sync_server& self; + socket_type sock; + boost::asio::io_service::work work; + + lambda(int id_, http_sync_server& self_, + socket_type&& sock_) + : id(id_) + , self(self_) + , sock(std::move(sock_)) + , work(sock.get_io_service()) + { + } + + void operator()() + { + self.do_peer(id, std::move(sock)); + } + }; + void on_accept(error_code ec) { @@ -101,16 +123,7 @@ public: return; maybe_throw(ec, "accept"); static int id_ = 0; - std::thread{ - [ - id = ++id_, - this, - sock = std::move(sock_), - work = boost::asio::io_service::work{ios_} - ]() mutable - { - do_peer(id, std::move(sock)); - }}.detach(); + std::thread{lambda{++id_, *this, std::move(sock_)}}.detach(); acceptor_.async_accept(sock_, std::bind(&http_sync_server::on_accept, this, asio::placeholders::error)); diff --git a/examples/wsproto_sync_echo_peer.h b/examples/wsproto_sync_echo_peer.h index 991a2d8cb..6b2fe40bc 100644 --- a/examples/wsproto_sync_echo_peer.h +++ b/examples/wsproto_sync_echo_peer.h @@ -102,6 +102,28 @@ private: } } + struct lambda + { + int id; + sync_echo_peer& self; + socket_type sock; + boost::asio::io_service::work work; + + lambda(int id_, sync_echo_peer& self_, + socket_type&& sock_) + : id(id_) + , self(self_) + , sock(std::move(sock_)) + , work(sock.get_io_service()) + { + } + + void operator()() + { + self.do_peer(id, std::move(sock)); + } + }; + void on_accept(error_code ec) { @@ -109,16 +131,7 @@ private: return; maybe_throw(ec, "accept"); static int id_ = 0; - std::thread{ - [ - id = ++id_, - this, - sock = std::move(sock_), - work = boost::asio::io_service::work{ios_} - ]() mutable - { - do_peer(id, std::move(sock)); - }}.detach(); + std::thread{lambda{++id_, *this, std::move(sock_)}}.detach(); acceptor_.async_accept(sock_, std::bind(&sync_echo_peer::on_accept, this, beast::asio::placeholders::error)); diff --git a/include/beast/async_completion.hpp b/include/beast/async_completion.hpp index d4be5428c..325e996bb 100644 --- a/include/beast/async_completion.hpp +++ b/include/beast/async_completion.hpp @@ -32,12 +32,12 @@ namespace beast { Usage: @code + ... template - auto + typename async_completion::result_type async_initfn(..., CompletionToken&& token) { - async_completion completion(token); + async_completion completion(token); ... return completion.result.get(); } @@ -46,7 +46,6 @@ namespace beast { See Library Foundations For Asynchronous Operations */ - template struct async_completion { @@ -59,12 +58,15 @@ struct async_completion typename boost::asio::handler_type< CompletionToken, Signature>::type; + using result_type = typename + boost::asio::async_result::type; + /** Construct the completion helper. @param token The completion token. Copies will be made as required. If `CompletionToken` is movable, it may also be moved. */ - async_completion(std::remove_reference_t& token) + async_completion(typename std::remove_reference::type& token) : handler(std::forward(token)) , result(handler) { diff --git a/include/beast/bind_handler.hpp b/include/beast/bind_handler.hpp index 6cc6225f7..e0dcdda2c 100644 --- a/include/beast/bind_handler.hpp +++ b/include/beast/bind_handler.hpp @@ -8,6 +8,7 @@ #ifndef BEAST_BIND_HANDLER_HPP #define BEAST_BIND_HANDLER_HPP +#include #include #include #include @@ -28,14 +29,14 @@ template class bound_handler { private: - using args_type = std::tuple...>; + using args_type = std::tuple::type...>; Handler h_; args_type args_; template static void invoke(Handler& h, Tuple& args, - std::index_sequence ) + index_sequence) { h(std::get(args)...); } @@ -55,14 +56,14 @@ public: operator()() { invoke(h_, args_, - std::index_sequence_for ()); + index_sequence_for ()); } void operator()() const { invoke(h_, args_, - std::index_sequence_for ()); + index_sequence_for ()); } friend @@ -133,19 +134,19 @@ public: @param handler The handler to wrap. @param args A list of arguments to bind to the handler. The - arguments are forwarded into the returned - + arguments are forwarded into the returned object. */ template #if GENERATING_DOCS implementation_defined #else -detail::bound_handler, Args...> +detail::bound_handler< + typename std::decay::type, Args...> #endif bind_handler(CompletionHandler&& handler, Args&&... args) { - return detail::bound_handler, Args...>(std::forward< + return detail::bound_handler::type, Args...>(std::forward< CompletionHandler>(handler), std::forward(args)...); } diff --git a/include/beast/buffer_cat.hpp b/include/beast/buffer_cat.hpp index 40a556fda..bfbb2d2e3 100644 --- a/include/beast/buffer_cat.hpp +++ b/include/beast/buffer_cat.hpp @@ -79,8 +79,8 @@ class buffer_cat_helper< using C = std::integral_constant; template - using iter_t = typename std::tuple_element_t< - I, std::tuple>::const_iterator; + using iter_t = typename std::tuple_element< + I, std::tuple>::type::const_iterator; template iter_t& @@ -491,7 +491,8 @@ implementation_defined buffer_cat(BufferSequence const&... buffers) #else template -auto +detail::buffer_cat_helper< + boost::asio::const_buffer, B1, B2, Bn...> buffer_cat(B1 const& b1, B2 const& b2, Bn const&... bn) #endif { diff --git a/include/beast/buffers_adapter.hpp b/include/beast/buffers_adapter.hpp index 85856b140..b6c6f3697 100644 --- a/include/beast/buffers_adapter.hpp +++ b/include/beast/buffers_adapter.hpp @@ -36,7 +36,7 @@ template class buffers_adapter { private: - using buffers_type = std::decay_t; + using buffers_type = typename std::decay::type; using iter_type = typename buffers_type::const_iterator; static auto constexpr is_mutable = diff --git a/include/beast/detail/ci_char_traits.hpp b/include/beast/detail/ci_char_traits.hpp index 0e4d6377e..8484f273f 100644 --- a/include/beast/detail/ci_char_traits.hpp +++ b/include/beast/detail/ci_char_traits.hpp @@ -45,8 +45,10 @@ bool ci_equal(std::pair lhs, std::pair rhs) { + if(lhs.second != rhs.second) + return false; return std::equal (lhs.first, lhs.first + lhs.second, - rhs.first, rhs.first + rhs.second, + rhs.first, [] (char lhs, char rhs) { return std::tolower(lhs) == std::tolower(rhs); diff --git a/include/beast/detail/integer_sequence.hpp b/include/beast/detail/integer_sequence.hpp new file mode 100644 index 000000000..73389c53b --- /dev/null +++ b/include/beast/detail/integer_sequence.hpp @@ -0,0 +1,145 @@ +// +// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef BEAST_DETAIL_INTEGER_SEQUENCE_H_INCLUDED +#define BEAST_DETAIL_INTEGER_SEQUENCE_H_INCLUDED + +#include +#include +#include + +namespace beast { +namespace detail { + +template +struct integer_sequence +{ + using value_type = T; + static_assert (std::is_integral::value, + "std::integer_sequence can only be instantiated with an integral type" ); + + static std::size_t constexpr static_size = sizeof...(Ints); + + static std::size_t constexpr size() + { + return sizeof...(Ints); + } +}; + +template +using index_sequence = integer_sequence; + +// This workaround is needed for broken sizeof... +template +struct sizeof_workaround +{ + static std::size_t constexpr size = sizeof... (Args); +}; + +#ifdef _MSC_VER + +// This implementation compiles on MSVC and clang but not gcc + +template +struct make_integer_sequence_unchecked; + +template +struct make_integer_sequence_unchecked< + T, N, integer_sequence> +{ + using type = typename make_integer_sequence_unchecked< + T, N-1, integer_sequence>::type; +}; + +template +struct make_integer_sequence_unchecked< + T, 0, integer_sequence> +{ + using type = integer_sequence; +}; + +template +struct make_integer_sequence_checked +{ + static_assert (std::is_integral::value, + "T must be an integral type"); + + static_assert (N >= 0, + "N must be non-negative"); + + using type = typename make_integer_sequence_unchecked< + T, N, integer_sequence>::type; +}; + +template +using make_integer_sequence = + typename make_integer_sequence_checked::type; + +template +using make_index_sequence = make_integer_sequence; + +template +using index_sequence_for = + make_index_sequence::size>; + +#else + +// This implementation compiles on gcc but not MSVC + +template +struct index_tuple +{ + using next = index_tuple; + +}; + +template +struct build_index_tuple +{ + using type = typename build_index_tuple::type::next; +}; + +template<> +struct build_index_tuple<0> +{ + using type = index_tuple<>; +}; + +template::type +> +struct integer_sequence_helper; + +template +struct integer_sequence_helper> +{ + static_assert (std::is_integral::value, + "T must be an integral type"); + + static_assert (N >= 0, + "N must be non-negative"); + + using type = integer_sequence (Ints)...>; +}; + +template +using make_integer_sequence = + typename integer_sequence_helper::type; + +template +using make_index_sequence = make_integer_sequence; + +template +using index_sequence_for = + make_index_sequence::size>; + +#endif + +} // detail +} // beast + +#endif diff --git a/include/beast/detail/stream/basic_scoped_ostream.hpp b/include/beast/detail/stream/basic_scoped_ostream.hpp index fcd34d6b6..262f3cd42 100644 --- a/include/beast/detail/stream/basic_scoped_ostream.hpp +++ b/include/beast/detail/stream/basic_scoped_ostream.hpp @@ -78,7 +78,7 @@ public: explicit basic_scoped_ostream (Handler&& handler) : m_handler (std::forward (handler)) #if BEAST_NO_STDLIB_STREAM_MOVE - , m_ss (std::make_unique ()) + , m_ss (new stream_type()) #endif { } @@ -87,7 +87,7 @@ public: basic_scoped_ostream (T const& t, Handler&& handler) : m_handler (std::forward (handler)) #if BEAST_NO_STDLIB_STREAM_MOVE - , m_ss (std::make_unique ()) + , m_ss (new stream_type()) #endif { stream() << t; diff --git a/include/beast/http.hpp b/include/beast/http.hpp index 591c32bb0..61db5985c 100644 --- a/include/beast/http.hpp +++ b/include/beast/http.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/include/beast/http/basic_headers.hpp b/include/beast/http/basic_headers.hpp index cf1f77530..6bbff654d 100644 --- a/include/beast/http/basic_headers.hpp +++ b/include/beast/http/basic_headers.hpp @@ -393,8 +393,8 @@ public: extended as per RFC2616 Section 4.2. */ template::value>> + class = typename std::enable_if< + ! std::is_constructible::value>::type> void insert(boost::string_ref name, T const& value) { @@ -417,8 +417,8 @@ public: specified value is inserted as if by insert(field, value). */ template::value>> + class = typename std::enable_if< + ! std::is_constructible::value>::type> void replace(boost::string_ref const& name, T const& value) { diff --git a/include/beast/http/chunk_encode.hpp b/include/beast/http/chunk_encode.hpp index 15ae2a427..13944fbd4 100644 --- a/include/beast/http/chunk_encode.hpp +++ b/include/beast/http/chunk_encode.hpp @@ -61,7 +61,8 @@ private: // Unchecked conversion of unsigned to hex string template static - std::enable_if_t::value, OutIter> + typename std::enable_if< + std::is_unsigned::value, OutIter>::type to_hex(OutIter const first, OutIter const last, Unsigned n); }; @@ -114,7 +115,8 @@ chunk_encoded_buffers::chunk_encoded_buffers ( template template -std::enable_if_t::value, OutIter> +typename std::enable_if< + std::is_unsigned::value, OutIter>::type chunk_encoded_buffers::to_hex( OutIter const first, OutIter const last, Unsigned n) { diff --git a/include/beast/http/detail/error.hpp b/include/beast/http/detail/error.hpp index a1543d988..414664eff 100644 --- a/include/beast/http/detail/error.hpp +++ b/include/beast/http/detail/error.hpp @@ -57,7 +57,7 @@ public: }; template -auto +boost::system::error_code make_error(int http_errno) { static message_category const mc{}; diff --git a/include/beast/http/detail/writes.hpp b/include/beast/http/detail/writes.hpp index d887a95c0..bd68bb2c9 100644 --- a/include/beast/http/detail/writes.hpp +++ b/include/beast/http/detail/writes.hpp @@ -20,7 +20,8 @@ namespace http { namespace detail { template::value>> + class = typename std::enable_if< + is_Streambuf::value>::type> void write(Streambuf& streambuf, T&& t) { @@ -34,8 +35,8 @@ write(Streambuf& streambuf, T&& t) } template0) && - is_Streambuf::value>> + class = typename std::enable_if< (N>0) && + is_Streambuf::value>::type> void write(Streambuf& streambuf, char const(&s)[N]) { @@ -46,7 +47,8 @@ write(Streambuf& streambuf, char const(&s)[N]) } template::value>> + class = typename std::enable_if< + is_Streambuf::value>::type> void write(Streambuf& streambuf, boost::string_ref const& s) { diff --git a/include/beast/http/fields.hpp b/include/beast/http/fields.hpp deleted file mode 100644 index e1eeb7104..000000000 --- a/include/beast/http/fields.hpp +++ /dev/null @@ -1,133 +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_FIELDS_H_INCLUDED -#define BEAST_HTTP_FIELDS_H_INCLUDED - -#include - -namespace beast { -namespace http { - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wmissing-braces" -#endif // defined(__clang__) - -template -auto const& -common_fields() -{ - // Must be sorted - static std::array constexpr h{ - "Accept" - ,"Accept-Charset" - ,"Accept-Datetime" - ,"Accept-Encoding" - ,"Accept-Language" - ,"Accept-Ranges" - ,"Access-Control-Allow-Credentials" - ,"Access-Control-Allow-Headers" - ,"Access-Control-Allow-Methods" - ,"Access-Control-Allow-Origin" - ,"Access-Control-Expose-Headers" - ,"Access-Control-Max-Age" - ,"Access-Control-Request-Headers" - ,"Access-Control-Request-Method" - ,"Age" - ,"Allow" - ,"Authorization" - ,"Cache-Control" - ,"Connection" - ,"Content-Disposition" - ,"Content-Encoding" - ,"Content-Language" - ,"Content-Length" - ,"Content-Location" - ,"Content-MD5" - ,"Content-Range" - ,"Content-Type" - ,"Cookie" - ,"DNT" - ,"Date" - ,"ETag" - ,"Expect" - ,"Expires" - ,"From" - ,"Front-End-Https" - ,"Host" - ,"If-Match" - ,"If-Modified-Since" - ,"If-None-Match" - ,"If-Range" - ,"If-Unmodified-Since" - ,"Keep-Alive" - ,"Last-Modified" - ,"Link" - ,"Location" - ,"Max-Forwards" - ,"Origin" - ,"P3P" - ,"Pragma" - ,"Proxy-Authenticate" - ,"Proxy-Authorization" - ,"Proxy-Connection" - ,"Range" - ,"Referer" - ,"Refresh" - ,"Retry-After" - ,"Server" - ,"Set-Cookie" - ,"Strict-Transport-Security" - ,"TE" - ,"Timestamp" - ,"Trailer" - ,"Transfer-Encoding" - ,"Upgrade" - ,"User-Agent" - ,"VIP" - ,"Vary" - ,"Via" - ,"WWW-Authenticate" - ,"Warning" - ,"X-Accel-Redirect" - ,"X-Content-Security-Policy-Report-Only" - ,"X-Content-Type-Options" - ,"X-Forwarded-For" - ,"X-Forwarded-Proto" - ,"X-Frame-Options" - ,"X-Powered-By" - ,"X-Real-IP" - ,"X-Requested-With" - ,"X-UA-Compatible" - ,"X-Wap-Profile" - ,"X-XSS-Protection" - }; - - return h; -} - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif // defined(__clang__) - -} // http -} // beast - -#endif diff --git a/include/beast/http/impl/message.ipp b/include/beast/http/impl/message.ipp index 7984b3b83..8e25a6c64 100644 --- a/include/beast/http/impl/message.ipp +++ b/include/beast/http/impl/message.ipp @@ -127,6 +127,31 @@ buffers_to_string(ConstBufferSequence const& buffers) return s; } +class writef_ostream +{ + std::ostream& os_; + bool chunked_; + +public: + writef_ostream(std::ostream& os, bool chunked) + : os_(os) + , chunked_(chunked) + { + } + + template + void + operator()(ConstBufferSequence const& buffers) + { + if(chunked_) + os_ << buffers_to_string( + chunk_encode(buffers)); + else + os_ << buffers_to_string( + buffers); + } +}; + } // detail // Diagnostic output only @@ -155,16 +180,7 @@ operator<<(std::ostream& os, auto copy = resume; os << detail::buffers_to_string(wp.sb.data()); wp.sb.consume(wp.sb.size()); - auto writef = - [&os, &wp](auto const& buffers) - { - if(wp.chunked) - os << detail::buffers_to_string( - chunk_encode(buffers)); - else - os << detail::buffers_to_string( - buffers); - }; + detail::writef_ostream writef(os, wp.chunked); for(;;) { { diff --git a/include/beast/http/impl/read.ipp b/include/beast/http/impl/read.ipp index 0022f184d..4c5b86d04 100644 --- a/include/beast/http/impl/read.ipp +++ b/include/beast/http/impl/read.ipp @@ -9,7 +9,6 @@ #define BEAST_HTTP_IMPL_READ_IPP_HPP #include -#include #include #include #include @@ -76,7 +75,7 @@ public: std::size_t bytes_transferred, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, read_op* op) { return boost_asio_handler_alloc_helpers:: @@ -84,7 +83,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, read_op* op) { return boost_asio_handler_alloc_helpers:: @@ -92,14 +91,14 @@ public: } friend - auto asio_handler_is_continuation(read_op* op) + bool asio_handler_is_continuation(read_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, read_op* op) + void asio_handler_invoke(Function&& f, read_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); @@ -258,11 +257,12 @@ read(SyncReadStream& stream, Streambuf& streambuf, template -auto + class ReadHandler> +typename async_completion< + ReadHandler, void(error_code)>::result_type async_read(AsyncReadStream& stream, Streambuf& streambuf, message& m, - CompletionToken&& token) + ReadHandler&& handler) { static_assert(is_AsyncReadStream::value, "AsyncReadStream requirements not met"); @@ -270,8 +270,8 @@ async_read(AsyncReadStream& stream, Streambuf& streambuf, "Streambuf requirements not met"); static_assert(is_ReadableBody::value, "ReadableBody requirements not met"); - beast::async_completion completion(token); + beast::async_completion completion(handler); detail::read_op{completion.handler, diff --git a/include/beast/http/impl/write.ipp b/include/beast/http/impl/write.ipp index 30852e2ef..a1839a290 100644 --- a/include/beast/http/impl/write.ipp +++ b/include/beast/http/impl/write.ipp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -61,6 +60,60 @@ class write_op } }; + class writef0 + { + write_op& self_; + + public: + explicit + writef0(write_op& self) + : self_(self) + { + } + + template + void operator()(ConstBufferSequence const& buffers) + { + auto& d = *self_.d_; + // write headers and body + if(d.wp.chunked) + boost::asio::async_write(d.s, + buffer_cat(d.wp.sb.data(), + chunk_encode(buffers)), + std::move(self_)); + else + boost::asio::async_write(d.s, + buffer_cat(d.wp.sb.data(), + buffers), std::move(self_)); + } + }; + + class writef + { + write_op& self_; + + public: + explicit + writef(write_op& self) + : self_(self) + { + } + + template + void operator()(ConstBufferSequence const& buffers) + { + auto& d = *self_.d_; + // write body + if(d.wp.chunked) + boost::asio::async_write(d.s, + chunk_encode(buffers), + std::move(self_)); + else + boost::asio::async_write(d.s, + buffers, std::move(self_)); + } + }; + std::shared_ptr d_; public: @@ -74,9 +127,11 @@ public: std::forward(args)...)) { auto& d = *d_; + auto sp = d_; d.resume = { - [self = *this]() mutable + [sp]() mutable { + write_op self(std::move(sp)); self.d_->cont = false; auto& ios = self.d_->s.get_io_service(); ios.dispatch(bind_handler(std::move(self), @@ -97,7 +152,7 @@ public: std::size_t bytes_transferred, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, write_op* op) { return boost_asio_handler_alloc_helpers:: @@ -105,7 +160,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, write_op* op) { return boost_asio_handler_alloc_helpers:: @@ -113,14 +168,14 @@ public: } friend - auto asio_handler_is_continuation(write_op* op) + bool asio_handler_is_continuation(write_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, write_op* op) + void asio_handler_invoke(Function&& f, write_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); @@ -156,20 +211,8 @@ operator()(error_code ec, std::size_t, bool again) case 1: { - auto const result = d.wp.w(std::move(d.copy), ec, - [&](auto const& buffers) - { - // write headers and body - if(d.wp.chunked) - boost::asio::async_write(d.s, - buffer_cat(d.wp.sb.data(), - chunk_encode(buffers)), - std::move(*this)); - else - boost::asio::async_write(d.s, - buffer_cat(d.wp.sb.data(), - buffers), std::move(*this)); - }); + auto const result = d.wp.w( + std::move(d.copy), ec, writef0{*this}); if(ec) { // call handler @@ -199,18 +242,8 @@ operator()(error_code ec, std::size_t, bool again) case 3: { - auto const result = d.wp.w(std::move(d.copy), ec, - [&](auto const& buffers) - { - // write body - if(d.wp.chunked) - boost::asio::async_write(d.s, - chunk_encode(buffers), - std::move(*this)); - else - boost::asio::async_write(d.s, - buffers, std::move(*this)); - }); + auto const result = d.wp.w( + std::move(d.copy), ec, writef{*this}); if(ec) { // call handler @@ -256,6 +289,65 @@ operator()(error_code ec, std::size_t, bool again) d.copy = {}; } +template +class writef0_write +{ + Streambuf const& sb_; + SyncWriteStream& stream_; + bool chunked_; + error_code& ec_; + +public: + writef0_write(SyncWriteStream& stream, + Streambuf const& sb, bool chunked, error_code& ec) + : sb_(sb) + , stream_(stream) + , chunked_(chunked) + , ec_(ec) + { + } + + template + void operator()(ConstBufferSequence const& buffers) + { + // write headers and body + if(chunked_) + boost::asio::write(stream_, buffer_cat( + sb_.data(), chunk_encode(buffers)), ec_); + else + boost::asio::write(stream_, buffer_cat( + sb_.data(), buffers), ec_); + } +}; + +template +class writef_write +{ + SyncWriteStream& stream_; + bool chunked_; + error_code& ec_; + +public: + writef_write(SyncWriteStream& stream, + bool chunked, error_code& ec) + : stream_(stream) + , chunked_(chunked) + , ec_(ec) + { + } + + template + void operator()(ConstBufferSequence const& buffers) + { + // write body + if(chunked_) + boost::asio::write(stream_, + chunk_encode(buffers), ec_); + else + boost::asio::write(stream_, buffers, ec_); + } +}; + } // detail //------------------------------------------------------------------------------ @@ -288,16 +380,8 @@ write(SyncWriteStream& stream, { { auto result = wp.w(std::move(copy), ec, - [&](auto const& buffers) - { - // write headers and body - if(wp.chunked) - boost::asio::write(stream, buffer_cat( - wp.sb.data(), chunk_encode(buffers)), ec); - else - boost::asio::write(stream, buffer_cat( - wp.sb.data(), buffers), ec); - }); + detail::writef0_write{ + stream, wp.sb, wp.chunked, ec}); if(ec) return; if(result) @@ -318,15 +402,8 @@ write(SyncWriteStream& stream, for(;;) { auto result = wp.w(std::move(copy), ec, - [&](auto const& buffers) - { - // write body - if(wp.chunked) - boost::asio::write(stream, - chunk_encode(buffers), ec); - else - boost::asio::write(stream, buffers, ec); - }); + detail::writef_write{ + stream, wp.chunked, ec}); if(ec) return; if(result) @@ -360,19 +437,20 @@ write(SyncWriteStream& stream, template -auto + class WriteHandler> +typename async_completion< + WriteHandler, void(error_code)>::result_type async_write(AsyncWriteStream& stream, message const& msg, - CompletionToken&& token) + WriteHandler&& handler) { static_assert( is_AsyncWriteStream::value, "AsyncWriteStream requirements not met"); static_assert(is_WritableBody::value, "WritableBody requirements not met"); - beast::async_completion completion(token); + beast::async_completion completion(handler); detail::write_op{completion.handler, stream, msg}; return completion.result.get(); diff --git a/include/beast/http/message.hpp b/include/beast/http/message.hpp index e1756a395..b31991e06 100644 --- a/include/beast/http/message.hpp +++ b/include/beast/http/message.hpp @@ -66,8 +66,8 @@ struct response_params */ template struct message - : std::conditional_t + : std::conditional::type { /** The trait type characterizing the body. diff --git a/include/beast/http/read.hpp b/include/beast/http/read.hpp index 9532cdee0..6b2ef3ab9 100644 --- a/include/beast/http/read.hpp +++ b/include/beast/http/read.hpp @@ -8,6 +8,7 @@ #ifndef BEAST_HTTP_READ_HPP #define BEAST_HTTP_READ_HPP +#include #include #include #include @@ -76,7 +77,7 @@ read(SyncReadStream& stream, Streambuf& streambuf, @param msg An object used to store the read message. Any contents will be overwritten. - @param token The handler to be called when the request completes. + @param handler The handler to be called when the request completes. Copies will be made of the handler as required. The equivalent function signature of the handler must be: @code void handler( @@ -89,15 +90,16 @@ read(SyncReadStream& stream, Streambuf& streambuf, */ template + class ReadHandler> #if GENERATING_DOCS void_or_deduced #else -auto +typename async_completion< + ReadHandler, void(error_code)>::result_type #endif async_read(AsyncReadStream& stream, Streambuf& streambuf, message& msg, - CompletionToken&& token); + ReadHandler&& handler); } // http } // beast diff --git a/include/beast/http/rfc2616.hpp b/include/beast/http/rfc2616.hpp index ea43016c7..254eca983 100644 --- a/include/beast/http/rfc2616.hpp +++ b/include/beast/http/rfc2616.hpp @@ -429,13 +429,12 @@ ci_equal(boost::string_ref s1, boost::string_ref s2) /** Returns a range representing the list. */ inline -auto +boost::iterator_range make_list(boost::string_ref const& field) { return boost::iterator_range{ list_iterator{field.begin(), field.end()}, list_iterator{field.end(), field.end()}}; - } /** Returns true if the specified token exists in the list. diff --git a/include/beast/http/streambuf_body.hpp b/include/beast/http/streambuf_body.hpp index 7b2fe581e..7271da7db 100644 --- a/include/beast/http/streambuf_body.hpp +++ b/include/beast/http/streambuf_body.hpp @@ -80,12 +80,6 @@ struct basic_streambuf_body write(body_.data()); return true; } - - auto - data() const noexcept - { - return body_.data(); - } }; }; diff --git a/include/beast/http/write.hpp b/include/beast/http/write.hpp index 9544687b2..0489dda67 100644 --- a/include/beast/http/write.hpp +++ b/include/beast/http/write.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -73,15 +74,16 @@ write(SyncWriteStream& stream, */ template + class WriteHandler> #if GENERATING_DOCS void_or_deduced #else -auto +typename async_completion< + WriteHandler, void(error_code)>::result_type #endif async_write(AsyncWriteStream& stream, message const& msg, - CompletionToken&& token); + WriteHandler&& handler); } // http } // beast diff --git a/include/beast/impl/streambuf_readstream.ipp b/include/beast/impl/streambuf_readstream.ipp index 9c52df411..e35e9313a 100644 --- a/include/beast/impl/streambuf_readstream.ipp +++ b/include/beast/impl/streambuf_readstream.ipp @@ -8,7 +8,6 @@ #ifndef BEAST_IMPL_STREAMBUF_READSTREAM_IPP #define BEAST_IMPL_STREAMBUF_READSTREAM_IPP -#include #include #include #include @@ -61,7 +60,7 @@ public: std::size_t bytes_transferred); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, read_some_op* op) { return boost_asio_handler_alloc_helpers:: @@ -69,7 +68,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, read_some_op* op) { return boost_asio_handler_alloc_helpers:: @@ -77,7 +76,7 @@ public: } friend - auto asio_handler_is_continuation(read_some_op* op) + bool asio_handler_is_continuation(read_some_op* op) { return boost_asio_handler_cont_helpers:: is_continuation(op->d_->h); @@ -85,7 +84,7 @@ public: template friend - auto asio_handler_invoke(Function&& f, read_some_op* op) + void asio_handler_invoke(Function&& f, read_some_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); @@ -170,7 +169,9 @@ template auto streambuf_readstream:: async_write_some(ConstBufferSequence const& buffers, - WriteHandler&& handler) + WriteHandler&& handler) -> + typename async_completion< + WriteHandler, void(error_code)>::result_type { static_assert(is_ConstBufferSequence< ConstBufferSequence>::value, @@ -234,7 +235,9 @@ auto streambuf_readstream:: async_read_some( MutableBufferSequence const& buffers, - ReadHandler&& handler) + ReadHandler&& handler) -> + typename async_completion< + ReadHandler, void(error_code)>::result_type { static_assert(is_MutableBufferSequence< MutableBufferSequence>::value, diff --git a/include/beast/streambuf_readstream.hpp b/include/beast/streambuf_readstream.hpp index 8b5bb7705..7d88ee81c 100644 --- a/include/beast/streambuf_readstream.hpp +++ b/include/beast/streambuf_readstream.hpp @@ -8,6 +8,7 @@ #ifndef BEAST_STREAMBUF_READSTREAM_HPP #define BEAST_STREAMBUF_READSTREAM_HPP +#include #include #include #include @@ -101,7 +102,7 @@ public: /// The type of the next layer. using next_layer_type = - std::remove_reference_t; + typename std::remove_reference::type; /// The type of the lowest layer. using lowest_layer_type = @@ -215,7 +216,8 @@ public: /// Start an asynchronous write. The data being written must be valid for the /// lifetime of the asynchronous operation. template - auto + typename async_completion< + WriteHandler, void(error_code)>::result_type async_write_some(ConstBufferSequence const& buffers, WriteHandler&& handler); @@ -235,7 +237,8 @@ public: /// Start an asynchronous read. The buffer into which the data will be read /// must be valid for the lifetime of the asynchronous operation. template - auto + typename async_completion< + ReadHandler, void(error_code)>::result_type async_read_some(MutableBufferSequence const& buffers, ReadHandler&& handler); }; diff --git a/include/beast/type_check.hpp b/include/beast/type_check.hpp index 16dfa8c84..43c49f9b3 100644 --- a/include/beast/type_check.hpp +++ b/include/beast/type_check.hpp @@ -338,7 +338,7 @@ public: /// Determine if `T` meets the requirements of `CompletionHandler`. template using is_Handler = std::integral_constant>::value && + std::is_copy_constructible::type>::value && detail::is_call_possible::value>; #endif diff --git a/include/beast/websocket/detail/invokable.hpp b/include/beast/websocket/detail/invokable.hpp index 37053fc8f..d049df65b 100644 --- a/include/beast/websocket/detail/invokable.hpp +++ b/include/beast/websocket/detail/invokable.hpp @@ -134,7 +134,7 @@ private: base& get() { - return *reinterpret_cast(buf_); + return *reinterpret_cast(&buf_[0]); } }; diff --git a/include/beast/websocket/detail/mask.hpp b/include/beast/websocket/detail/mask.hpp index f5ebaddd7..e37fdca50 100644 --- a/include/beast/websocket/detail/mask.hpp +++ b/include/beast/websocket/detail/mask.hpp @@ -106,28 +106,28 @@ prepare_key(std::uint64_t& prepared, std::uint32_t key) template inline -std::enable_if_t::value, T> +typename std::enable_if::value, T>::type rol(T t, unsigned n = 1) { auto constexpr bits = static_cast( sizeof(T) * CHAR_BIT); n &= bits-1; - return static_cast((t << n) | - (static_cast>(t) >> (bits - n))); + return static_cast((t << n) | ( + static_cast::type>(t) >> (bits - n))); } template inline -std::enable_if_t::value, T> +typename std::enable_if::value, T>::type ror(T t, unsigned n = 1) { auto constexpr bits = static_cast( sizeof(T) * CHAR_BIT); n &= bits-1; - return static_cast((t << (bits - n)) | - (static_cast>(t) >> n)); + return static_cast((t << (bits - n)) | ( + static_cast::type>(t) >> n)); } // 32-bit Uuoptimized diff --git a/include/beast/websocket/detail/stream_base.hpp b/include/beast/websocket/detail/stream_base.hpp index 42eab6890..743951ecc 100644 --- a/include/beast/websocket/detail/stream_base.hpp +++ b/include/beast/websocket/detail/stream_base.hpp @@ -97,8 +97,7 @@ protected: close_reason cr_; // set from received close frame stream_base() - : d_(std::make_unique< - decorator>()) + : d_(new decorator{}) { } diff --git a/include/beast/websocket/impl/accept_op.ipp b/include/beast/websocket/impl/accept_op.ipp index ff8b03d1d..c4e6dc97f 100644 --- a/include/beast/websocket/impl/accept_op.ipp +++ b/include/beast/websocket/impl/accept_op.ipp @@ -78,7 +78,7 @@ public: std::size_t bytes_transferred, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, accept_op* op) { return boost_asio_handler_alloc_helpers:: @@ -86,7 +86,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, accept_op* op) { return boost_asio_handler_alloc_helpers:: @@ -94,14 +94,14 @@ public: } friend - auto asio_handler_is_continuation(accept_op* op) + bool asio_handler_is_continuation(accept_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, accept_op* op) + void asio_handler_invoke(Function&& f, accept_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); diff --git a/include/beast/websocket/impl/close_op.ipp b/include/beast/websocket/impl/close_op.ipp index 1b558686a..c3201903c 100644 --- a/include/beast/websocket/impl/close_op.ipp +++ b/include/beast/websocket/impl/close_op.ipp @@ -85,7 +85,7 @@ public: std::size_t bytes_transferred, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, close_op* op) { return boost_asio_handler_alloc_helpers:: @@ -93,7 +93,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, close_op* op) { return boost_asio_handler_alloc_helpers:: @@ -101,14 +101,14 @@ public: } friend - auto asio_handler_is_continuation(close_op* op) + bool asio_handler_is_continuation(close_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, close_op* op) + void asio_handler_invoke(Function&& f, close_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); diff --git a/include/beast/websocket/impl/handshake_op.ipp b/include/beast/websocket/impl/handshake_op.ipp index a3cd9e552..a2179f369 100644 --- a/include/beast/websocket/impl/handshake_op.ipp +++ b/include/beast/websocket/impl/handshake_op.ipp @@ -76,7 +76,7 @@ public: std::size_t bytes_transferred, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, handshake_op* op) { return boost_asio_handler_alloc_helpers:: @@ -84,7 +84,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, handshake_op* op) { return boost_asio_handler_alloc_helpers:: @@ -92,14 +92,14 @@ public: } friend - auto asio_handler_is_continuation(handshake_op* op) + bool asio_handler_is_continuation(handshake_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, handshake_op* op) + void asio_handler_invoke(Function&& f, handshake_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); diff --git a/include/beast/websocket/impl/read_frame_op.ipp b/include/beast/websocket/impl/read_frame_op.ipp index e29feda00..82e2da98a 100644 --- a/include/beast/websocket/impl/read_frame_op.ipp +++ b/include/beast/websocket/impl/read_frame_op.ipp @@ -94,7 +94,7 @@ public: std::size_t bytes_transferred, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, read_frame_op* op) { return boost_asio_handler_alloc_helpers:: @@ -102,7 +102,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, read_frame_op* op) { return boost_asio_handler_alloc_helpers:: @@ -110,14 +110,14 @@ public: } friend - auto asio_handler_is_continuation(read_frame_op* op) + bool asio_handler_is_continuation(read_frame_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, read_frame_op* op) + void asio_handler_invoke(Function&& f, read_frame_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); diff --git a/include/beast/websocket/impl/read_op.ipp b/include/beast/websocket/impl/read_op.ipp index b42c401b0..8ea868935 100644 --- a/include/beast/websocket/impl/read_op.ipp +++ b/include/beast/websocket/impl/read_op.ipp @@ -67,7 +67,7 @@ public: error_code const& ec, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, read_op* op) { return boost_asio_handler_alloc_helpers:: @@ -75,7 +75,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, read_op* op) { return boost_asio_handler_alloc_helpers:: @@ -83,14 +83,14 @@ public: } friend - auto asio_handler_is_continuation(read_op* op) + bool asio_handler_is_continuation(read_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, read_op* op) + void asio_handler_invoke(Function&& f, read_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); diff --git a/include/beast/websocket/impl/response_op.ipp b/include/beast/websocket/impl/response_op.ipp index 9351c2b27..dd7343cda 100644 --- a/include/beast/websocket/impl/response_op.ipp +++ b/include/beast/websocket/impl/response_op.ipp @@ -68,7 +68,7 @@ public: error_code ec, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, response_op* op) { return boost_asio_handler_alloc_helpers:: @@ -76,7 +76,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, response_op* op) { return boost_asio_handler_alloc_helpers:: @@ -84,14 +84,14 @@ public: } friend - auto asio_handler_is_continuation(response_op* op) + bool asio_handler_is_continuation(response_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, response_op* op) + void asio_handler_invoke(Function&& f, response_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); diff --git a/include/beast/websocket/impl/ssl.ipp b/include/beast/websocket/impl/ssl.ipp index 4e9440a8a..5f054f281 100644 --- a/include/beast/websocket/impl/ssl.ipp +++ b/include/beast/websocket/impl/ssl.ipp @@ -73,7 +73,7 @@ public: operator()(error_code ec, bool again = true); friend - auto asio_handler_allocate(std::size_t size, + void* asio_handler_allocate(std::size_t size, teardown_ssl_op* op) { return boost_asio_handler_alloc_helpers:: @@ -81,7 +81,7 @@ public: } friend - auto asio_handler_deallocate(void* p, + void asio_handler_deallocate(void* p, std::size_t size, teardown_ssl_op* op) { return boost_asio_handler_alloc_helpers:: @@ -89,7 +89,7 @@ public: } friend - auto asio_handler_is_continuation( + bool asio_handler_is_continuation( teardown_ssl_op* op) { return op->d_->cont; @@ -97,7 +97,7 @@ public: template friend - auto asio_handler_invoke(Function&& f, + void asio_handler_invoke(Function&& f, teardown_ssl_op* op) { return boost_asio_handler_invoke_helpers:: @@ -147,8 +147,8 @@ async_teardown( static_assert(beast::is_Handler< TeardownHandler, void(error_code)>::value, "TeardownHandler requirements not met"); - detail::teardown_ssl_op>{std::forward( + detail::teardown_ssl_op::type>{std::forward( handler), stream}; } diff --git a/include/beast/websocket/impl/socket.ipp b/include/beast/websocket/impl/stream.ipp similarity index 89% rename from include/beast/websocket/impl/socket.ipp rename to include/beast/websocket/impl/stream.ipp index 6d437540d..033c7a8b5 100644 --- a/include/beast/websocket/impl/socket.ipp +++ b/include/beast/websocket/impl/stream.ipp @@ -5,8 +5,8 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef BEAST_WEBSOCKET_IMPL_SOCKET_IPP -#define BEAST_WEBSOCKET_IMPL_SOCKET_IPP +#ifndef BEAST_WEBSOCKET_IMPL_STREAM_IPP +#define BEAST_WEBSOCKET_IMPL_STREAM_IPP #include #include @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -167,7 +166,8 @@ stream_base::write_ping(Streambuf& sb, template template -stream::stream(Args&&... args) +stream:: +stream(Args&&... args) : next_layer_(std::forward(args)...) , stream_(next_layer_) { @@ -177,15 +177,18 @@ stream::stream(Args&&... args) template void -stream::accept(error_code& ec) +stream:: +accept(error_code& ec) { accept(boost::asio::null_buffers{}, ec); } template template -auto -stream::async_accept(AcceptHandler&& handler) +typename async_completion< + AcceptHandler, void(error_code)>::result_type +stream:: +async_accept(AcceptHandler&& handler) { return async_accept(boost::asio::null_buffers{}, std::forward(handler)); @@ -194,8 +197,8 @@ stream::async_accept(AcceptHandler&& handler) template template void -stream::accept( - ConstBufferSequence const& buffers) +stream:: +accept(ConstBufferSequence const& buffers) { static_assert(is_ConstBufferSequence< ConstBufferSequence>::value, @@ -208,8 +211,8 @@ stream::accept( template template void -stream::accept( - ConstBufferSequence const& buffers, error_code& ec) +stream:: +accept(ConstBufferSequence const& buffers, error_code& ec) { static_assert(beast::is_ConstBufferSequence< ConstBufferSequence>::value, @@ -228,9 +231,10 @@ stream::accept( template template -auto -stream::async_accept( - ConstBufferSequence const& bs, AcceptHandler&& handler) +typename async_completion< + AcceptHandler, void(error_code)>::result_type +stream:: +async_accept(ConstBufferSequence const& bs, AcceptHandler&& handler) { static_assert(beast::is_ConstBufferSequence< ConstBufferSequence>::value, @@ -246,8 +250,8 @@ stream::async_accept( template template void -stream::accept( - http::message const& request) +stream:: +accept(http::message const& request) { error_code ec; accept(request, ec); @@ -257,9 +261,9 @@ stream::accept( template template void -stream::accept( - http::message const& req, - error_code& ec) +stream:: +accept(http::message const& req, + error_code& ec) { auto resp = build_response(req); http::write(stream_, resp, ec); @@ -275,10 +279,11 @@ stream::accept( template template -auto -stream::async_accept( - http::message const& req, - AcceptHandler&& handler) +typename async_completion< + AcceptHandler, void(error_code)>::result_type +stream:: +async_accept(http::message const& req, + AcceptHandler&& handler) { beast::async_completion< AcceptHandler, void(error_code) @@ -292,7 +297,8 @@ stream::async_accept( template void -stream::handshake(boost::string_ref const& host, +stream:: +handshake(boost::string_ref const& host, boost::string_ref const& resource, error_code& ec) { std::string key; @@ -309,8 +315,10 @@ stream::handshake(boost::string_ref const& host, template template -auto -stream::async_handshake(boost::string_ref const& host, +typename async_completion< + HandshakeHandler, void(error_code)>::result_type +stream:: +async_handshake(boost::string_ref const& host, boost::string_ref const& resource, HandshakeHandler&& handler) { beast::async_completion< @@ -323,8 +331,8 @@ stream::async_handshake(boost::string_ref const& host, template void -stream::close( - close_reason const& cr, error_code& ec) +stream:: +close(close_reason const& cr, error_code& ec) { assert(! wr_close_); wr_close_ = true; @@ -336,9 +344,10 @@ stream::close( template template -auto -stream::async_close( - close_reason const& cr, CloseHandler&& handler) +typename async_completion< + CloseHandler, void(error_code)>::result_type +stream:: +async_close(close_reason const& cr, CloseHandler&& handler) { beast::async_completion< CloseHandler, void(error_code) @@ -368,7 +377,8 @@ read(opcode& op, Streambuf& streambuf, error_code& ec) template template -auto +typename async_completion< + ReadHandler, void(error_code)>::result_type stream:: async_read(opcode& op, Streambuf& streambuf, ReadHandler&& handler) @@ -386,8 +396,8 @@ async_read(opcode& op, template template void -stream::read_frame(frame_info& fi, - Streambuf& streambuf, error_code& ec) +stream:: +read_frame(frame_info& fi, Streambuf& streambuf, error_code& ec) { close_code code{}; for(;;) @@ -521,8 +531,10 @@ stream::read_frame(frame_info& fi, template template -auto -stream::async_read_frame(frame_info& fi, +typename async_completion< + ReadHandler, void(error_code)>::result_type +stream:: +async_read_frame(frame_info& fi, Streambuf& streambuf, ReadHandler&& handler) { static_assert(beast::is_Streambuf::value, @@ -537,8 +549,8 @@ stream::async_read_frame(frame_info& fi, template template void -stream::write( - ConstBufferSequence const& bs, error_code& ec) +stream:: +write(ConstBufferSequence const& bs, error_code& ec) { static_assert(beast::is_ConstBufferSequence< ConstBufferSequence>::value, @@ -563,9 +575,10 @@ stream::write( template template -auto -stream::async_write( - ConstBufferSequence const& bs, WriteHandler&& handler) +typename async_completion< + WriteHandler, void(error_code)>::result_type +stream:: +async_write(ConstBufferSequence const& bs, WriteHandler&& handler) { static_assert(beast::is_ConstBufferSequence< ConstBufferSequence>::value, @@ -580,8 +593,8 @@ stream::async_write( template template void -stream::write_frame(bool fin, - ConstBufferSequence const& bs, error_code& ec) +stream:: +write_frame(bool fin, ConstBufferSequence const& bs, error_code& ec) { static_assert(beast::is_ConstBufferSequence< ConstBufferSequence>::value, @@ -656,8 +669,10 @@ stream::write_frame(bool fin, template template -auto -stream::async_write_frame(bool fin, +typename async_completion< + WriteHandler, void(error_code)>::result_type +stream:: +async_write_frame(bool fin, ConstBufferSequence const& bs, WriteHandler&& handler) { static_assert(beast::is_ConstBufferSequence< @@ -676,7 +691,8 @@ stream::async_write_frame(bool fin, template http::request -stream::build_request(boost::string_ref const& host, +stream:: +build_request(boost::string_ref const& host, boost::string_ref const& resource, std::string& key) { http::request req; @@ -696,11 +712,11 @@ stream::build_request(boost::string_ref const& host, template template http::response -stream::build_response( - http::message const& req) +stream:: +build_response(http::message const& req) { auto err = - [&](auto const& text) + [&](std::string const& text) { http::response resp( {400, http::reason_string(400), req.version}); @@ -748,9 +764,9 @@ stream::build_response( template template void -stream::do_response( - http::message const& resp, - boost::string_ref const& key, error_code& ec) +stream:: +do_response(http::message const& resp, + boost::string_ref const& key, error_code& ec) { // VFALCO Review these error codes auto fail = [&]{ ec = error::response_failed; }; @@ -771,9 +787,9 @@ stream::do_response( template void -stream::do_read_fh( - detail::frame_streambuf& fb, - close_code& code, error_code& ec) +stream:: +do_read_fh(detail::frame_streambuf& fb, + close_code& code, error_code& ec) { fb.commit(boost::asio::read( stream_, fb.prepare(2), ec)); diff --git a/include/beast/websocket/impl/teardown.ipp b/include/beast/websocket/impl/teardown.ipp index e11992a6a..689f647ea 100644 --- a/include/beast/websocket/impl/teardown.ipp +++ b/include/beast/websocket/impl/teardown.ipp @@ -61,7 +61,7 @@ public: error_code ec, std::size_t, bool again = true); friend - auto asio_handler_allocate(std::size_t size, + void* asio_handler_allocate(std::size_t size, teardown_tcp_op* op) { return boost_asio_handler_alloc_helpers:: @@ -69,7 +69,7 @@ public: } friend - auto asio_handler_deallocate(void* p, + void asio_handler_deallocate(void* p, std::size_t size, teardown_tcp_op* op) { return boost_asio_handler_alloc_helpers:: @@ -77,14 +77,14 @@ public: } friend - auto asio_handler_is_continuation(teardown_tcp_op* op) + bool asio_handler_is_continuation(teardown_tcp_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, + void asio_handler_invoke(Function&& f, teardown_tcp_op* op) { return boost_asio_handler_invoke_helpers:: @@ -160,8 +160,8 @@ async_teardown( static_assert(beast::is_Handler< TeardownHandler, void(error_code)>::value, "TeardownHandler requirements not met"); - detail::teardown_tcp_op>{std::forward< + detail::teardown_tcp_op::type>{std::forward< TeardownHandler>(handler), socket}; } diff --git a/include/beast/websocket/impl/write_frame_op.ipp b/include/beast/websocket/impl/write_frame_op.ipp index 3d0f72a18..41f669a0a 100644 --- a/include/beast/websocket/impl/write_frame_op.ipp +++ b/include/beast/websocket/impl/write_frame_op.ipp @@ -113,7 +113,7 @@ public: std::size_t bytes_transferred, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, write_frame_op* op) { return boost_asio_handler_alloc_helpers:: @@ -121,7 +121,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, write_frame_op* op) { return boost_asio_handler_alloc_helpers:: @@ -129,14 +129,14 @@ public: } friend - auto asio_handler_is_continuation(write_frame_op* op) + bool asio_handler_is_continuation(write_frame_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, write_frame_op* op) + void asio_handler_invoke(Function&& f, write_frame_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); diff --git a/include/beast/websocket/impl/write_op.ipp b/include/beast/websocket/impl/write_op.ipp index 50fa14d43..0a4b3e0d2 100644 --- a/include/beast/websocket/impl/write_op.ipp +++ b/include/beast/websocket/impl/write_op.ipp @@ -70,7 +70,7 @@ public: void operator()(error_code ec, bool again = true); friend - auto asio_handler_allocate( + void* asio_handler_allocate( std::size_t size, write_op* op) { return boost_asio_handler_alloc_helpers:: @@ -78,7 +78,7 @@ public: } friend - auto asio_handler_deallocate( + void asio_handler_deallocate( void* p, std::size_t size, write_op* op) { return boost_asio_handler_alloc_helpers:: @@ -86,14 +86,14 @@ public: } friend - auto asio_handler_is_continuation(write_op* op) + bool asio_handler_is_continuation(write_op* op) { return op->d_->cont; } template friend - auto asio_handler_invoke(Function&& f, write_op* op) + void asio_handler_invoke(Function&& f, write_op* op) { return boost_asio_handler_invoke_helpers:: invoke(f, op->d_->h); diff --git a/include/beast/websocket/option.hpp b/include/beast/websocket/option.hpp index 3f872f650..9dda1f6c2 100644 --- a/include/beast/websocket/option.hpp +++ b/include/beast/websocket/option.hpp @@ -99,12 +99,12 @@ using decorate = implementation_defined; #else template inline -auto +detail::decorator_type decorate(Decorator&& d) { - return std::make_unique>>( - std::forward(d)); + return detail::decorator_type{new + detail::decorator::type>{ + std::forward(d)}}; } #endif diff --git a/include/beast/websocket/stream.hpp b/include/beast/websocket/stream.hpp index 537242aa8..c5a7bc82b 100644 --- a/include/beast/websocket/stream.hpp +++ b/include/beast/websocket/stream.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -85,7 +86,7 @@ class stream : public detail::stream_base public: /// The type of the next layer. using next_layer_type = - std::remove_reference_t; + typename std::remove_reference::type; /// The type of the lowest layer. using lowest_layer_type = @@ -365,7 +366,8 @@ public: manner equivalent to using boost::asio::io_service::post(). */ template - auto + typename async_completion< + AcceptHandler, void(error_code)>::result_type async_accept(AcceptHandler&& handler); /** Read and respond to a WebSocket HTTP Upgrade request. @@ -465,7 +467,8 @@ public: manner equivalent to using boost::asio::io_service::post(). */ template - auto + typename async_completion< + AcceptHandler, void(error_code)>::result_type async_accept(ConstBufferSequence const& buffers, AcceptHandler&& handler); @@ -560,7 +563,8 @@ public: manner equivalent to using boost::asio::io_service::post(). */ template - auto + typename async_completion< + AcceptHandler, void(error_code)>::result_type async_accept(http::message const& request, AcceptHandler&& handler); @@ -666,7 +670,8 @@ public: manner equivalent to using boost::asio::io_service::post(). */ template - auto + typename async_completion< + HandshakeHandler, void(error_code)>::result_type async_handshake(boost::string_ref const& host, boost::string_ref const& resource, HandshakeHandler&& h); @@ -745,7 +750,8 @@ public: manner equivalent to using boost::asio::io_service::post(). */ template - auto + typename async_completion< + CloseHandler, void(error_code)>::result_type async_close(close_reason const& cr, CloseHandler&& handler); /** Read a message. @@ -829,7 +835,8 @@ public: #if GENERATING_DOCS void_or_deduced #else - auto + typename async_completion< + ReadHandler, void(error_code)>::result_type #endif async_read(opcode& op, Streambuf& streambuf, ReadHandler&& handler); @@ -938,7 +945,8 @@ public: manner equivalent to using boost::asio::io_service::post(). */ template - auto + typename async_completion< + ReadHandler, void(error_code)>::result_type async_read_frame(frame_info& fi, Streambuf& streambuf, ReadHandler&& handler); @@ -1041,7 +1049,8 @@ public: #if GENERATING_DOCS void_or_deduced #else - auto + typename async_completion< + WriteHandler, void(error_code)>::result_type #endif async_write(ConstBufferSequence const& buffers, WriteHandler&& handler); @@ -1140,7 +1149,8 @@ public: ); @endcode */ template - auto + typename async_completion< + WriteHandler, void(error_code)>::result_type async_write_frame(bool fin, ConstBufferSequence const& buffers, WriteHandler&& handler); @@ -1176,6 +1186,6 @@ private: } // websocket } // beast -#include +#include #endif diff --git a/test/Jamfile b/test/Jamfile index 2a37683be..31a36b38a 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -15,7 +15,6 @@ unit-test http_tests : http/chunk_encode.cpp http/empty_body.cpp http/error.cpp - http/fields.cpp http/headers.cpp http/message.cpp http/method.cpp diff --git a/test/buffer_cat.cpp b/test/buffer_cat.cpp index 88cb5004c..6c4879156 100644 --- a/test/buffer_cat.cpp +++ b/test/buffer_cat.cpp @@ -21,6 +21,13 @@ namespace test { class buffer_cat_test : public detail::unit_test::suite { public: + template< class Iterator > + static + std::reverse_iterator + make_reverse_iterator( Iterator i ) + { + return std::reverse_iterator(i); + } void testBufferCat() { @@ -43,8 +50,8 @@ public: b1, b2, b3, b4, b5, b6); expect(buffer_size(bs) == 10); std::vector v; - for(auto iter = std::make_reverse_iterator(bs.end()); - iter != std::make_reverse_iterator(bs.begin()); ++iter) + for(auto iter = make_reverse_iterator(bs.end()); + iter != make_reverse_iterator(bs.begin()); ++iter) v.emplace_back(*iter); expect(buffer_size(bs) == 10); decltype(bs) bs2(bs); diff --git a/test/http/fields.cpp b/test/http/fields.cpp deleted file mode 100644 index 4a0f5fa81..000000000 --- a/test/http/fields.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// -// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com) -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// - -// Test that header file is self-contained. -#include