Reduce requirements to C++11 only

This commit is contained in:
Vinnie Falco
2016-04-22 07:34:44 -04:00
parent 0061f03cef
commit af3d721f82
50 changed files with 625 additions and 452 deletions

View File

@@ -53,14 +53,15 @@ project beast
<library>/boost/system//boost_system
<library>/boost/filesystem//boost_filesystem
<library>/boost/program_options//boost_program_options
# <library>ssl
# <library>crypto
# <library>ssl
# <library>crypto
<define>BOOST_ALL_NO_LIB=1
<define>BOOST_SYSTEM_NO_DEPRECATED=1
<threading>multi
<link>static
<runtime-link>shared
<toolset>gcc:<cxxflags>-std=c++14
<toolset>clang:<cxxflags>-std=c++14
<toolset>gcc:<cxxflags>-std=c++11
<toolset>clang:<cxxflags>-std=c++11
<os>LINUX:<define>_XOPEN_SOURCE=600
<os>LINUX:<define>_GNU_SOURCE=1
<os>SOLARIS:<define>_XOPEN_SOURCE=500

View File

@@ -69,7 +69,7 @@ struct file_body
size_ = boost::filesystem::file_size(path_);
}
auto
std::size_t
content_length() const
{
return size_;

View File

@@ -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()

View File

@@ -21,6 +21,7 @@
#define BEAST_HTTP_STREAM_H_INCLUDED
#include <beast/http.hpp>
#include <beast/async_completion.hpp>
#include <beast/basic_streambuf.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/intrusive/list.hpp>
@@ -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<NextLayer>;
typename std::remove_reference<NextLayer>::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<isRequest, Body, Headers>& 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<isRequest, Body, Headers> 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<isRequest, Body, Headers>&& msg,
WriteHandler&& handler);

View File

@@ -20,7 +20,6 @@
#ifndef BEAST_HTTP_STREAM_IPP_INCLUDED
#define BEAST_HTTP_STREAM_IPP_INCLUDED
#include <beast/async_completion.hpp>
#include <beast/bind_handler.hpp>
#include <beast/handler_alloc.hpp>
#include <beast/http/read.hpp>
@@ -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 <class Function>
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 <class Function>
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<bool isRequest, class Body, class Headers,
auto
stream<NextLayer, Allocator>::
async_read(message<isRequest, Body, Headers>& 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<bool isRequest, class Body, class Headers,
auto
stream<NextLayer, Allocator>::
async_write(message<isRequest, Body, Headers> 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<bool isRequest, class Body, class Headers,
auto
stream<NextLayer, Allocator>::
async_write(message<isRequest, Body, Headers>&& msg,
WriteHandler&& handler)
WriteHandler&& handler) ->
typename async_completion<
WriteHandler, void(error_code)>::result_type
{
async_completion<
WriteHandler, void(error_code)> completion(handler);

View File

@@ -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));

View File

@@ -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));

View File

@@ -32,12 +32,12 @@ namespace beast {
Usage:
@code
...
template<class CompletionToken>
auto
typename async_completion<CompletionToken, Signature>::result_type
async_initfn(..., CompletionToken&& token)
{
async_completion<CompletionToken,
void(error_code, std::size_t)> completion(token);
async_completion<CompletionToken, Signature> completion(token);
...
return completion.result.get();
}
@@ -46,7 +46,6 @@ namespace beast {
See <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3896.pdf">
Library Foundations For Asynchronous Operations</a>
*/
template <class CompletionToken, class Signature>
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<handler_type>::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<CompletionToken>& token)
async_completion(typename std::remove_reference<CompletionToken>::type& token)
: handler(std::forward<CompletionToken>(token))
, result(handler)
{

View File

@@ -8,6 +8,7 @@
#ifndef BEAST_BIND_HANDLER_HPP
#define BEAST_BIND_HANDLER_HPP
#include <beast/detail/integer_sequence.hpp>
#include <boost/asio/detail/handler_alloc_helpers.hpp>
#include <boost/asio/detail/handler_cont_helpers.hpp>
#include <boost/asio/detail/handler_invoke_helpers.hpp>
@@ -28,14 +29,14 @@ template<class Handler, class... Args>
class bound_handler
{
private:
using args_type = std::tuple<std::decay_t<Args>...>;
using args_type = std::tuple<typename std::decay<Args>::type...>;
Handler h_;
args_type args_;
template<class Tuple, std::size_t... S>
static void invoke(Handler& h, Tuple& args,
std::index_sequence <S...>)
index_sequence<S...>)
{
h(std::get<S>(args)...);
}
@@ -55,14 +56,14 @@ public:
operator()()
{
invoke(h_, args_,
std::index_sequence_for<Args...> ());
index_sequence_for<Args...> ());
}
void
operator()() const
{
invoke(h_, args_,
std::index_sequence_for<Args...> ());
index_sequence_for<Args...> ());
}
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<class CompletionHandler, class... Args>
#if GENERATING_DOCS
implementation_defined
#else
detail::bound_handler<std::decay_t<CompletionHandler>, Args...>
detail::bound_handler<
typename std::decay<CompletionHandler>::type, Args...>
#endif
bind_handler(CompletionHandler&& handler, Args&&... args)
{
return detail::bound_handler<std::decay_t<
CompletionHandler>, Args...>(std::forward<
return detail::bound_handler<typename std::decay<
CompletionHandler>::type, Args...>(std::forward<
CompletionHandler>(handler),
std::forward<Args>(args)...);
}

View File

@@ -79,8 +79,8 @@ class buffer_cat_helper<
using C = std::integral_constant<std::size_t, I>;
template<std::size_t I>
using iter_t = typename std::tuple_element_t<
I, std::tuple<Bs...>>::const_iterator;
using iter_t = typename std::tuple_element<
I, std::tuple<Bs...>>::type::const_iterator;
template<std::size_t I>
iter_t<I>&
@@ -491,7 +491,8 @@ implementation_defined
buffer_cat(BufferSequence const&... buffers)
#else
template<class B1, class B2, class... Bn>
auto
detail::buffer_cat_helper<
boost::asio::const_buffer, B1, B2, Bn...>
buffer_cat(B1 const& b1, B2 const& b2, Bn const&... bn)
#endif
{

View File

@@ -36,7 +36,7 @@ template<class Buffers>
class buffers_adapter
{
private:
using buffers_type = std::decay_t<Buffers>;
using buffers_type = typename std::decay<Buffers>::type;
using iter_type = typename buffers_type::const_iterator;
static auto constexpr is_mutable =

View File

@@ -45,8 +45,10 @@ bool
ci_equal(std::pair<const char*, std::size_t> lhs,
std::pair<const char*, std::size_t> 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);

View File

@@ -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 <cstddef>
#include <type_traits>
#include <utility>
namespace beast {
namespace detail {
template<class T, T... Ints>
struct integer_sequence
{
using value_type = T;
static_assert (std::is_integral<T>::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<std::size_t... Ints>
using index_sequence = integer_sequence<std::size_t, Ints...>;
// This workaround is needed for broken sizeof...
template<class... Args>
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<class T, unsigned long long N, class Seq>
struct make_integer_sequence_unchecked;
template<class T, unsigned long long N, unsigned long long ...Indices>
struct make_integer_sequence_unchecked<
T, N, integer_sequence<T, Indices...>>
{
using type = typename make_integer_sequence_unchecked<
T, N-1, integer_sequence<T, N-1, Indices...>>::type;
};
template<class T, unsigned long long ...Indices>
struct make_integer_sequence_unchecked<
T, 0, integer_sequence<T, Indices...>>
{
using type = integer_sequence<T, Indices...>;
};
template<class T, T N>
struct make_integer_sequence_checked
{
static_assert (std::is_integral<T>::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<T>>::type;
};
template<class T, T N>
using make_integer_sequence =
typename make_integer_sequence_checked<T, N>::type;
template<std::size_t N>
using make_index_sequence = make_integer_sequence<std::size_t, N>;
template<class... Args>
using index_sequence_for =
make_index_sequence<sizeof_workaround<Args...>::size>;
#else
// This implementation compiles on gcc but not MSVC
template<std::size_t... Ints>
struct index_tuple
{
using next = index_tuple<Ints..., sizeof... (Ints)>;
};
template<std::size_t N>
struct build_index_tuple
{
using type = typename build_index_tuple<N-1>::type::next;
};
template<>
struct build_index_tuple<0>
{
using type = index_tuple<>;
};
template<class T, T N,
class Seq = typename build_index_tuple<N>::type
>
struct integer_sequence_helper;
template<class T, T N, std::size_t... Ints>
struct integer_sequence_helper<T, N, index_tuple<Ints...>>
{
static_assert (std::is_integral<T>::value,
"T must be an integral type");
static_assert (N >= 0,
"N must be non-negative");
using type = integer_sequence<T, static_cast<T> (Ints)...>;
};
template<class T, T N>
using make_integer_sequence =
typename integer_sequence_helper<T, N>::type;
template<std::size_t N>
using make_index_sequence = make_integer_sequence<std::size_t, N>;
template<class... Args>
using index_sequence_for =
make_index_sequence<sizeof_workaround<Args...>::size>;
#endif
} // detail
} // beast
#endif

View File

@@ -78,7 +78,7 @@ public:
explicit basic_scoped_ostream (Handler&& handler)
: m_handler (std::forward <Handler> (handler))
#if BEAST_NO_STDLIB_STREAM_MOVE
, m_ss (std::make_unique <stream_type>())
, m_ss (new stream_type())
#endif
{
}
@@ -87,7 +87,7 @@ public:
basic_scoped_ostream (T const& t, Handler&& handler)
: m_handler (std::forward <Handler> (handler))
#if BEAST_NO_STDLIB_STREAM_MOVE
, m_ss (std::make_unique <stream_type>())
, m_ss (new stream_type())
#endif
{
stream() << t;

View File

@@ -13,7 +13,6 @@
#include <beast/http/chunk_encode.hpp>
#include <beast/http/empty_body.hpp>
#include <beast/http/error.hpp>
#include <beast/http/fields.hpp>
#include <beast/http/headers.hpp>
#include <beast/http/message.hpp>
#include <beast/http/parser.hpp>

View File

@@ -393,8 +393,8 @@ public:
extended as per RFC2616 Section 4.2.
*/
template<class T,
class = std::enable_if_t<
! std::is_constructible<boost::string_ref, T>::value>>
class = typename std::enable_if<
! std::is_constructible<boost::string_ref, T>::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<class T,
class = std::enable_if_t<
! std::is_constructible<boost::string_ref, T>::value>>
class = typename std::enable_if<
! std::is_constructible<boost::string_ref, T>::value>::type>
void
replace(boost::string_ref const& name, T const& value)
{

View File

@@ -61,7 +61,8 @@ private:
// Unchecked conversion of unsigned to hex string
template<class OutIter, class Unsigned>
static
std::enable_if_t<std::is_unsigned<Unsigned>::value, OutIter>
typename std::enable_if<
std::is_unsigned<Unsigned>::value, OutIter>::type
to_hex(OutIter const first, OutIter const last, Unsigned n);
};
@@ -114,7 +115,8 @@ chunk_encoded_buffers<Buffers>::chunk_encoded_buffers (
template <class Buffers>
template <class OutIter, class Unsigned>
std::enable_if_t<std::is_unsigned<Unsigned>::value, OutIter>
typename std::enable_if<
std::is_unsigned<Unsigned>::value, OutIter>::type
chunk_encoded_buffers<Buffers>::to_hex(
OutIter const first, OutIter const last, Unsigned n)
{

View File

@@ -57,7 +57,7 @@ public:
};
template<class = void>
auto
boost::system::error_code
make_error(int http_errno)
{
static message_category const mc{};

View File

@@ -20,7 +20,8 @@ namespace http {
namespace detail {
template<class Streambuf, class T,
class = std::enable_if_t<is_Streambuf<Streambuf>::value>>
class = typename std::enable_if<
is_Streambuf<Streambuf>::value>::type>
void
write(Streambuf& streambuf, T&& t)
{
@@ -34,8 +35,8 @@ write(Streambuf& streambuf, T&& t)
}
template<class Streambuf, std::size_t N,
class = std::enable_if_t< (N>0) &&
is_Streambuf<Streambuf>::value>>
class = typename std::enable_if< (N>0) &&
is_Streambuf<Streambuf>::value>::type>
void
write(Streambuf& streambuf, char const(&s)[N])
{
@@ -46,7 +47,8 @@ write(Streambuf& streambuf, char const(&s)[N])
}
template<class Streambuf,
class = std::enable_if_t<is_Streambuf<Streambuf>::value>>
class = typename std::enable_if<
is_Streambuf<Streambuf>::value>::type>
void
write(Streambuf& streambuf, boost::string_ref const& s)
{

View File

@@ -1,133 +0,0 @@
//------------------------------------------------------------------------------
/*
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
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 <array>
namespace beast {
namespace http {
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-braces"
#endif // defined(__clang__)
template<class = void>
auto const&
common_fields()
{
// Must be sorted
static std::array<char const*, 82> 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

View File

@@ -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<class ConstBufferSequence>
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(;;)
{
{

View File

@@ -9,7 +9,6 @@
#define BEAST_HTTP_IMPL_READ_IPP_HPP
#include <beast/http/type_check.hpp>
#include <beast/async_completion.hpp>
#include <beast/bind_handler.hpp>
#include <beast/handler_alloc.hpp>
#include <cassert>
@@ -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 <class Function>
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<class AsyncReadStream, class Streambuf,
bool isRequest, class Body, class Headers,
class CompletionToken>
auto
class ReadHandler>
typename async_completion<
ReadHandler, void(error_code)>::result_type
async_read(AsyncReadStream& stream, Streambuf& streambuf,
message<isRequest, Body, Headers>& m,
CompletionToken&& token)
ReadHandler&& handler)
{
static_assert(is_AsyncReadStream<AsyncReadStream>::value,
"AsyncReadStream requirements not met");
@@ -270,8 +270,8 @@ async_read(AsyncReadStream& stream, Streambuf& streambuf,
"Streambuf requirements not met");
static_assert(is_ReadableBody<Body>::value,
"ReadableBody requirements not met");
beast::async_completion<CompletionToken,
void(error_code)> completion(token);
beast::async_completion<ReadHandler,
void(error_code)> completion(handler);
detail::read_op<AsyncReadStream, Streambuf,
isRequest, Body, Headers, decltype(
completion.handler)>{completion.handler,

View File

@@ -14,7 +14,6 @@
#include <beast/http/detail/writes.hpp>
#include <beast/http/detail/write_preparation.hpp>
#include <beast/buffer_cat.hpp>
#include <beast/async_completion.hpp>
#include <beast/bind_handler.hpp>
#include <beast/handler_alloc.hpp>
#include <beast/streambuf.hpp>
@@ -61,6 +60,60 @@ class write_op
}
};
class writef0
{
write_op& self_;
public:
explicit
writef0(write_op& self)
: self_(self)
{
}
template<class ConstBufferSequence>
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<class ConstBufferSequence>
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<data> d_;
public:
@@ -74,9 +127,11 @@ public:
std::forward<Args>(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 <class Function>
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 SyncWriteStream, class Streambuf>
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<class ConstBufferSequence>
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 SyncWriteStream>
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<class ConstBufferSequence>
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<SyncWriteStream, decltype(wp.sb)>{
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<SyncWriteStream>{
stream, wp.chunked, ec});
if(ec)
return;
if(result)
@@ -360,19 +437,20 @@ write(SyncWriteStream& stream,
template<class AsyncWriteStream,
bool isRequest, class Body, class Headers,
class CompletionToken>
auto
class WriteHandler>
typename async_completion<
WriteHandler, void(error_code)>::result_type
async_write(AsyncWriteStream& stream,
message<isRequest, Body, Headers> const& msg,
CompletionToken&& token)
WriteHandler&& handler)
{
static_assert(
is_AsyncWriteStream<AsyncWriteStream>::value,
"AsyncWriteStream requirements not met");
static_assert(is_WritableBody<Body>::value,
"WritableBody requirements not met");
beast::async_completion<CompletionToken,
void(error_code)> completion(token);
beast::async_completion<WriteHandler,
void(error_code)> completion(handler);
detail::write_op<AsyncWriteStream, decltype(completion.handler),
isRequest, Body, Headers>{completion.handler, stream, msg};
return completion.result.get();

View File

@@ -66,8 +66,8 @@ struct response_params
*/
template<bool isRequest, class Body, class Headers>
struct message
: std::conditional_t<isRequest,
detail::request_fields, detail::response_fields>
: std::conditional<isRequest,
detail::request_fields, detail::response_fields>::type
{
/** The trait type characterizing the body.

View File

@@ -8,6 +8,7 @@
#ifndef BEAST_HTTP_READ_HPP
#define BEAST_HTTP_READ_HPP
#include <beast/async_completion.hpp>
#include <beast/http/error.hpp>
#include <beast/http/parser.hpp>
#include <beast/http/type_check.hpp>
@@ -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 AsyncReadStream, class Streambuf,
bool isRequest, class Body, class Headers,
class CompletionToken>
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<isRequest, Body, Headers>& msg,
CompletionToken&& token);
ReadHandler&& handler);
} // http
} // beast

View File

@@ -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<list_iterator>
make_list(boost::string_ref const& field)
{
return boost::iterator_range<list_iterator>{
list_iterator{field.begin(), field.end()},
list_iterator{field.end(), field.end()}};
}
/** Returns true if the specified token exists in the list.

View File

@@ -80,12 +80,6 @@ struct basic_streambuf_body
write(body_.data());
return true;
}
auto
data() const noexcept
{
return body_.data();
}
};
};

View File

@@ -10,6 +10,7 @@
#include <beast/http/error.hpp>
#include <beast/http/message.hpp>
#include <beast/async_completion.hpp>
#include <boost/system/error_code.hpp>
#include <type_traits>
@@ -73,15 +74,16 @@ write(SyncWriteStream& stream,
*/
template<class AsyncWriteStream,
bool isRequest, class Body, class Headers,
class CompletionToken>
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<isRequest, Body, Headers> const& msg,
CompletionToken&& token);
WriteHandler&& handler);
} // http
} // beast

View File

@@ -8,7 +8,6 @@
#ifndef BEAST_IMPL_STREAMBUF_READSTREAM_IPP
#define BEAST_IMPL_STREAMBUF_READSTREAM_IPP
#include <beast/async_completion.hpp>
#include <beast/bind_handler.hpp>
#include <beast/handler_alloc.hpp>
#include <beast/type_check.hpp>
@@ -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 <class Function>
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<class ConstBufferSequence, class WriteHandler>
auto
streambuf_readstream<Stream, Streambuf>::
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<Stream, Streambuf>::
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,

View File

@@ -8,6 +8,7 @@
#ifndef BEAST_STREAMBUF_READSTREAM_HPP
#define BEAST_STREAMBUF_READSTREAM_HPP
#include <beast/async_completion.hpp>
#include <beast/streambuf.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp>
@@ -101,7 +102,7 @@ public:
/// The type of the next layer.
using next_layer_type =
std::remove_reference_t<Stream>;
typename std::remove_reference<Stream>::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<class ConstBufferSequence, class WriteHandler>
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<class MutableBufferSequence, class ReadHandler>
auto
typename async_completion<
ReadHandler, void(error_code)>::result_type
async_read_some(MutableBufferSequence const& buffers,
ReadHandler&& handler);
};

View File

@@ -338,7 +338,7 @@ public:
/// Determine if `T` meets the requirements of `CompletionHandler`.
template<class T, class Signature>
using is_Handler = std::integral_constant<bool,
std::is_copy_constructible<std::decay_t<T>>::value &&
std::is_copy_constructible<typename std::decay<T>::type>::value &&
detail::is_call_possible<T, Signature>::value>;
#endif

View File

@@ -134,7 +134,7 @@ private:
base&
get()
{
return *reinterpret_cast<base*>(buf_);
return *reinterpret_cast<base*>(&buf_[0]);
}
};

View File

@@ -106,28 +106,28 @@ prepare_key(std::uint64_t& prepared, std::uint32_t key)
template<class T>
inline
std::enable_if_t<std::is_integral<T>::value, T>
typename std::enable_if<std::is_integral<T>::value, T>::type
rol(T t, unsigned n = 1)
{
auto constexpr bits =
static_cast<unsigned>(
sizeof(T) * CHAR_BIT);
n &= bits-1;
return static_cast<T>((t << n) |
(static_cast<std::make_unsigned_t<T>>(t) >> (bits - n)));
return static_cast<T>((t << n) | (
static_cast<typename std::make_unsigned<T>::type>(t) >> (bits - n)));
}
template <class T>
inline
std::enable_if_t<std::is_integral<T>::value, T>
typename std::enable_if<std::is_integral<T>::value, T>::type
ror(T t, unsigned n = 1)
{
auto constexpr bits =
static_cast<unsigned>(
sizeof(T) * CHAR_BIT);
n &= bits-1;
return static_cast<T>((t << (bits - n)) |
(static_cast<std::make_unsigned_t<T>>(t) >> n));
return static_cast<T>((t << (bits - n)) | (
static_cast<typename std::make_unsigned<T>::type>(t) >> n));
}
// 32-bit Uuoptimized

View File

@@ -97,8 +97,7 @@ protected:
close_reason cr_; // set from received close frame
stream_base()
: d_(std::make_unique<
decorator<default_decorator>>())
: d_(new decorator<default_decorator>{})
{
}

View File

@@ -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 <class Function>
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);

View File

@@ -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 <class Function>
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);

View File

@@ -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 <class Function>
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);

View File

@@ -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 <class Function>
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);

View File

@@ -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 <class Function>
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);

View File

@@ -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 <class Function>
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);

View File

@@ -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 <class Function>
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<AsyncStream, std::decay_t<
TeardownHandler>>{std::forward<TeardownHandler>(
detail::teardown_ssl_op<AsyncStream, typename std::decay<
TeardownHandler>::type>{std::forward<TeardownHandler>(
handler), stream};
}

View File

@@ -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 <beast/websocket/teardown.hpp>
#include <beast/websocket/detail/hybi13.hpp>
@@ -19,7 +19,6 @@
#include <beast/websocket/impl/write_op.ipp>
#include <beast/websocket/impl/write_frame_op.ipp>
#include <beast/buffer_cat.hpp>
#include <beast/async_completion.hpp>
#include <beast/consuming_buffers.hpp>
#include <beast/prepare_buffers.hpp>
#include <beast/static_streambuf.hpp>
@@ -167,7 +166,8 @@ stream_base::write_ping(Streambuf& sb,
template<class NextLayer>
template<class... Args>
stream<NextLayer>::stream(Args&&... args)
stream<NextLayer>::
stream(Args&&... args)
: next_layer_(std::forward<Args>(args)...)
, stream_(next_layer_)
{
@@ -177,15 +177,18 @@ stream<NextLayer>::stream(Args&&... args)
template<class NextLayer>
void
stream<NextLayer>::accept(error_code& ec)
stream<NextLayer>::
accept(error_code& ec)
{
accept(boost::asio::null_buffers{}, ec);
}
template<class NextLayer>
template<class AcceptHandler>
auto
stream<NextLayer>::async_accept(AcceptHandler&& handler)
typename async_completion<
AcceptHandler, void(error_code)>::result_type
stream<NextLayer>::
async_accept(AcceptHandler&& handler)
{
return async_accept(boost::asio::null_buffers{},
std::forward<AcceptHandler>(handler));
@@ -194,8 +197,8 @@ stream<NextLayer>::async_accept(AcceptHandler&& handler)
template<class NextLayer>
template<class ConstBufferSequence>
void
stream<NextLayer>::accept(
ConstBufferSequence const& buffers)
stream<NextLayer>::
accept(ConstBufferSequence const& buffers)
{
static_assert(is_ConstBufferSequence<
ConstBufferSequence>::value,
@@ -208,8 +211,8 @@ stream<NextLayer>::accept(
template<class NextLayer>
template<class ConstBufferSequence>
void
stream<NextLayer>::accept(
ConstBufferSequence const& buffers, error_code& ec)
stream<NextLayer>::
accept(ConstBufferSequence const& buffers, error_code& ec)
{
static_assert(beast::is_ConstBufferSequence<
ConstBufferSequence>::value,
@@ -228,9 +231,10 @@ stream<NextLayer>::accept(
template<class NextLayer>
template<class ConstBufferSequence, class AcceptHandler>
auto
stream<NextLayer>::async_accept(
ConstBufferSequence const& bs, AcceptHandler&& handler)
typename async_completion<
AcceptHandler, void(error_code)>::result_type
stream<NextLayer>::
async_accept(ConstBufferSequence const& bs, AcceptHandler&& handler)
{
static_assert(beast::is_ConstBufferSequence<
ConstBufferSequence>::value,
@@ -246,8 +250,8 @@ stream<NextLayer>::async_accept(
template<class NextLayer>
template<class Body, class Headers>
void
stream<NextLayer>::accept(
http::message<true, Body, Headers> const& request)
stream<NextLayer>::
accept(http::message<true, Body, Headers> const& request)
{
error_code ec;
accept(request, ec);
@@ -257,9 +261,9 @@ stream<NextLayer>::accept(
template<class NextLayer>
template<class Body, class Headers>
void
stream<NextLayer>::accept(
http::message<true, Body, Headers> const& req,
error_code& ec)
stream<NextLayer>::
accept(http::message<true, Body, Headers> const& req,
error_code& ec)
{
auto resp = build_response(req);
http::write(stream_, resp, ec);
@@ -275,10 +279,11 @@ stream<NextLayer>::accept(
template<class NextLayer>
template<class Body, class Headers, class AcceptHandler>
auto
stream<NextLayer>::async_accept(
http::message<true, Body, Headers> const& req,
AcceptHandler&& handler)
typename async_completion<
AcceptHandler, void(error_code)>::result_type
stream<NextLayer>::
async_accept(http::message<true, Body, Headers> const& req,
AcceptHandler&& handler)
{
beast::async_completion<
AcceptHandler, void(error_code)
@@ -292,7 +297,8 @@ stream<NextLayer>::async_accept(
template<class NextLayer>
void
stream<NextLayer>::handshake(boost::string_ref const& host,
stream<NextLayer>::
handshake(boost::string_ref const& host,
boost::string_ref const& resource, error_code& ec)
{
std::string key;
@@ -309,8 +315,10 @@ stream<NextLayer>::handshake(boost::string_ref const& host,
template<class NextLayer>
template<class HandshakeHandler>
auto
stream<NextLayer>::async_handshake(boost::string_ref const& host,
typename async_completion<
HandshakeHandler, void(error_code)>::result_type
stream<NextLayer>::
async_handshake(boost::string_ref const& host,
boost::string_ref const& resource, HandshakeHandler&& handler)
{
beast::async_completion<
@@ -323,8 +331,8 @@ stream<NextLayer>::async_handshake(boost::string_ref const& host,
template<class NextLayer>
void
stream<NextLayer>::close(
close_reason const& cr, error_code& ec)
stream<NextLayer>::
close(close_reason const& cr, error_code& ec)
{
assert(! wr_close_);
wr_close_ = true;
@@ -336,9 +344,10 @@ stream<NextLayer>::close(
template<class NextLayer>
template<class CloseHandler>
auto
stream<NextLayer>::async_close(
close_reason const& cr, CloseHandler&& handler)
typename async_completion<
CloseHandler, void(error_code)>::result_type
stream<NextLayer>::
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<class NextLayer>
template<class Streambuf, class ReadHandler>
auto
typename async_completion<
ReadHandler, void(error_code)>::result_type
stream<NextLayer>::
async_read(opcode& op,
Streambuf& streambuf, ReadHandler&& handler)
@@ -386,8 +396,8 @@ async_read(opcode& op,
template<class NextLayer>
template<class Streambuf>
void
stream<NextLayer>::read_frame(frame_info& fi,
Streambuf& streambuf, error_code& ec)
stream<NextLayer>::
read_frame(frame_info& fi, Streambuf& streambuf, error_code& ec)
{
close_code code{};
for(;;)
@@ -521,8 +531,10 @@ stream<NextLayer>::read_frame(frame_info& fi,
template<class NextLayer>
template<class Streambuf, class ReadHandler>
auto
stream<NextLayer>::async_read_frame(frame_info& fi,
typename async_completion<
ReadHandler, void(error_code)>::result_type
stream<NextLayer>::
async_read_frame(frame_info& fi,
Streambuf& streambuf, ReadHandler&& handler)
{
static_assert(beast::is_Streambuf<Streambuf>::value,
@@ -537,8 +549,8 @@ stream<NextLayer>::async_read_frame(frame_info& fi,
template<class NextLayer>
template<class ConstBufferSequence>
void
stream<NextLayer>::write(
ConstBufferSequence const& bs, error_code& ec)
stream<NextLayer>::
write(ConstBufferSequence const& bs, error_code& ec)
{
static_assert(beast::is_ConstBufferSequence<
ConstBufferSequence>::value,
@@ -563,9 +575,10 @@ stream<NextLayer>::write(
template<class NextLayer>
template<class ConstBufferSequence, class WriteHandler>
auto
stream<NextLayer>::async_write(
ConstBufferSequence const& bs, WriteHandler&& handler)
typename async_completion<
WriteHandler, void(error_code)>::result_type
stream<NextLayer>::
async_write(ConstBufferSequence const& bs, WriteHandler&& handler)
{
static_assert(beast::is_ConstBufferSequence<
ConstBufferSequence>::value,
@@ -580,8 +593,8 @@ stream<NextLayer>::async_write(
template<class NextLayer>
template<class ConstBufferSequence>
void
stream<NextLayer>::write_frame(bool fin,
ConstBufferSequence const& bs, error_code& ec)
stream<NextLayer>::
write_frame(bool fin, ConstBufferSequence const& bs, error_code& ec)
{
static_assert(beast::is_ConstBufferSequence<
ConstBufferSequence>::value,
@@ -656,8 +669,10 @@ stream<NextLayer>::write_frame(bool fin,
template<class NextLayer>
template<class ConstBufferSequence, class WriteHandler>
auto
stream<NextLayer>::async_write_frame(bool fin,
typename async_completion<
WriteHandler, void(error_code)>::result_type
stream<NextLayer>::
async_write_frame(bool fin,
ConstBufferSequence const& bs, WriteHandler&& handler)
{
static_assert(beast::is_ConstBufferSequence<
@@ -676,7 +691,8 @@ stream<NextLayer>::async_write_frame(bool fin,
template<class NextLayer>
http::request<http::empty_body>
stream<NextLayer>::build_request(boost::string_ref const& host,
stream<NextLayer>::
build_request(boost::string_ref const& host,
boost::string_ref const& resource, std::string& key)
{
http::request<http::empty_body> req;
@@ -696,11 +712,11 @@ stream<NextLayer>::build_request(boost::string_ref const& host,
template<class NextLayer>
template<class Body, class Headers>
http::response<http::string_body>
stream<NextLayer>::build_response(
http::message<true, Body, Headers> const& req)
stream<NextLayer>::
build_response(http::message<true, Body, Headers> const& req)
{
auto err =
[&](auto const& text)
[&](std::string const& text)
{
http::response<http::string_body> resp(
{400, http::reason_string(400), req.version});
@@ -748,9 +764,9 @@ stream<NextLayer>::build_response(
template<class NextLayer>
template<class Body, class Headers>
void
stream<NextLayer>::do_response(
http::message<false, Body, Headers> const& resp,
boost::string_ref const& key, error_code& ec)
stream<NextLayer>::
do_response(http::message<false, Body, Headers> 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<NextLayer>::do_response(
template<class NextLayer>
void
stream<NextLayer>::do_read_fh(
detail::frame_streambuf& fb,
close_code& code, error_code& ec)
stream<NextLayer>::
do_read_fh(detail::frame_streambuf& fb,
close_code& code, error_code& ec)
{
fb.commit(boost::asio::read(
stream_, fb.prepare(2), ec));

View File

@@ -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 <class Function>
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::decay_t<
TeardownHandler>>{std::forward<
detail::teardown_tcp_op<typename std::decay<
TeardownHandler>::type>{std::forward<
TeardownHandler>(handler), socket};
}

View File

@@ -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 <class Function>
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);

View File

@@ -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 <class Function>
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);

View File

@@ -99,12 +99,12 @@ using decorate = implementation_defined;
#else
template<class Decorator>
inline
auto
detail::decorator_type
decorate(Decorator&& d)
{
return std::make_unique<detail::decorator<
std::decay_t<Decorator>>>(
std::forward<Decorator>(d));
return detail::decorator_type{new
detail::decorator<typename std::decay<Decorator>::type>{
std::forward<Decorator>(d)}};
}
#endif

View File

@@ -11,6 +11,7 @@
#include <beast/websocket/option.hpp>
#include <beast/websocket/detail/stream_base.hpp>
#include <beast/streambuf_readstream.hpp>
#include <beast/async_completion.hpp>
#include <beast/http/message.hpp>
#include <beast/http/string_body.hpp>
#include <boost/asio.hpp>
@@ -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<NextLayer>;
typename std::remove_reference<NextLayer>::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<class AcceptHandler>
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<class ConstBufferSequence, class AcceptHandler>
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<class Body, class Headers, class AcceptHandler>
auto
typename async_completion<
AcceptHandler, void(error_code)>::result_type
async_accept(http::message<true,
Body, Headers> const& request, AcceptHandler&& handler);
@@ -666,7 +670,8 @@ public:
manner equivalent to using boost::asio::io_service::post().
*/
template<class HandshakeHandler>
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<class CloseHandler>
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<class Streambuf, class ReadHandler>
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<class ConstBufferSequence, class WriteHandler>
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 <beast/websocket/impl/socket.ipp>
#include <beast/websocket/impl/stream.ipp>
#endif

View File

@@ -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

View File

@@ -21,6 +21,13 @@ namespace test {
class buffer_cat_test : public detail::unit_test::suite
{
public:
template< class Iterator >
static
std::reverse_iterator<Iterator>
make_reverse_iterator( Iterator i )
{
return std::reverse_iterator<Iterator>(i);
}
void testBufferCat()
{
@@ -43,8 +50,8 @@ public:
b1, b2, b3, b4, b5, b6);
expect(buffer_size(bs) == 10);
std::vector<const_buffer> 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);

View File

@@ -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 <beast/http/fields.hpp>