accept requires a message

This commit is contained in:
Vinnie Falco
2017-07-14 13:00:09 -07:00
parent efd715e55c
commit 3c2d3181fc
5 changed files with 122 additions and 106 deletions

View File

@@ -6,6 +6,7 @@ WebSocket
* stream tidying
* Add rd_close_ to websocket stream state
* stream uses flat_buffer
* accept requires a message
--------------------------------------------------------------------------------

View File

@@ -42,24 +42,22 @@ class stream<NextLayer>::response_op
response_type res;
int state = 0;
template<class Allocator, class Decorator>
data(Handler&, stream<NextLayer>& ws_, http::header<
true, http::basic_fields<Allocator>> const& req,
Decorator const& decorator,
bool cont_)
template<class Body, class Allocator, class Decorator>
data(Handler&, stream<NextLayer>& ws_, http::request<
Body, http::basic_fields<Allocator>> const& req,
Decorator const& decorator, bool cont_)
: cont(cont_)
, ws(ws_)
, res(ws_.build_response(req, decorator))
{
}
template<class Allocator,
template<class Body, class Allocator,
class Buffers, class Decorator>
data(Handler&, stream<NextLayer>& ws_, http::header<
true, http::basic_fields<Allocator>> const& req,
Buffers const& buffers,
Decorator const& decorator,
bool cont_)
data(Handler&, stream<NextLayer>& ws_, http::request<
Body, http::basic_fields<Allocator>> const& req,
Buffers const& buffers, Decorator const& decorator,
bool cont_)
: cont(cont_)
, ws(ws_)
, res(ws_.build_response(req, decorator))
@@ -443,10 +441,10 @@ accept_ex(ConstBufferSequence const& buffers,
}
template<class NextLayer>
template<class Allocator>
template<class Body, class Allocator>
void
stream<NextLayer>::
accept(http::header<true,
accept(http::request<Body,
http::basic_fields<Allocator>> const& req)
{
static_assert(is_sync_stream<next_layer_type>::value,
@@ -458,10 +456,11 @@ accept(http::header<true,
}
template<class NextLayer>
template<class Allocator, class ResponseDecorator>
template<class Body,
class Allocator, class ResponseDecorator>
void
stream<NextLayer>::
accept_ex(http::header<true,
accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator)
{
@@ -477,10 +476,10 @@ accept_ex(http::header<true,
}
template<class NextLayer>
template<class Allocator>
template<class Body, class Allocator>
void
stream<NextLayer>::
accept(http::header<true,
accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
error_code& ec)
{
@@ -491,10 +490,11 @@ accept(http::header<true,
}
template<class NextLayer>
template<class Allocator, class ResponseDecorator>
template<class Body, class Allocator,
class ResponseDecorator>
void
stream<NextLayer>::
accept_ex(http::header<true,
accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, error_code& ec)
{
@@ -508,10 +508,11 @@ accept_ex(http::header<true,
}
template<class NextLayer>
template<class Allocator, class ConstBufferSequence>
template<class Body, class Allocator,
class ConstBufferSequence>
void
stream<NextLayer>::
accept(http::header<true,
accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers)
{
@@ -527,11 +528,11 @@ accept(http::header<true,
}
template<class NextLayer>
template<class Allocator,
template<class Body, class Allocator,
class ConstBufferSequence, class ResponseDecorator>
void
stream<NextLayer>::
accept_ex(http::header<true,
accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator)
@@ -551,11 +552,12 @@ accept_ex(http::header<true,
}
template<class NextLayer>
template<class Allocator, class ConstBufferSequence>
template<class Body, class Allocator,
class ConstBufferSequence>
void
stream<NextLayer>::
accept(http::header<true,
Allocator> const& req,
accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers, error_code& ec)
{
static_assert(is_sync_stream<next_layer_type>::value,
@@ -573,11 +575,11 @@ accept(http::header<true,
}
template<class NextLayer>
template<class Allocator,
template<class Body, class Allocator,
class ConstBufferSequence, class ResponseDecorator>
void
stream<NextLayer>::
accept_ex(http::header<true,
accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
@@ -696,11 +698,12 @@ async_accept_ex(ConstBufferSequence const& buffers,
}
template<class NextLayer>
template<class Allocator, class AcceptHandler>
template<class Body, class Allocator,
class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
stream<NextLayer>::
async_accept(http::header<true,
async_accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
AcceptHandler&& handler)
{
@@ -719,12 +722,12 @@ async_accept(http::header<true,
}
template<class NextLayer>
template<class Allocator,
template<class Body, class Allocator,
class ResponseDecorator, class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
stream<NextLayer>::
async_accept_ex(http::header<true,
async_accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator, AcceptHandler&& handler)
{
@@ -746,12 +749,12 @@ async_accept_ex(http::header<true,
}
template<class NextLayer>
template<class Allocator,
template<class Body, class Allocator,
class ConstBufferSequence, class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
stream<NextLayer>::
async_accept(http::header<true,
async_accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
AcceptHandler&& handler)
@@ -774,12 +777,13 @@ async_accept(http::header<true,
}
template<class NextLayer>
template<class Allocator, class ConstBufferSequence,
class ResponseDecorator, class AcceptHandler>
template<class Body, class Allocator,
class ConstBufferSequence, class ResponseDecorator,
class AcceptHandler>
async_return_type<
AcceptHandler, void(error_code)>
stream<NextLayer>::
async_accept_ex(http::header<true,
async_accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,

View File

@@ -501,10 +501,10 @@ build_request(detail::sec_ws_key_type& key,
}
template<class NextLayer>
template<class Allocator, class Decorator>
template<class Body, class Allocator, class Decorator>
response_type
stream<NextLayer>::
build_response(http::header<true,
build_response(http::request<Body,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator)
{
@@ -598,10 +598,11 @@ do_accept(
}
template<class NextLayer>
template<class Allocator, class Decorator>
template<class Body, class Allocator,
class Decorator>
void
stream<NextLayer>::
do_accept(http::header<true,
do_accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator, error_code& ec)
{
@@ -652,7 +653,7 @@ do_handshake(response_type* res_p,
template<class NextLayer>
void
stream<NextLayer>::
do_response(http::header<false> const& res,
do_response(response_type const& res,
detail::sec_ws_key_type const& key, error_code& ec)
{
bool const success = [&]()

View File

@@ -999,9 +999,10 @@ public:
@throws system_error Thrown on failure.
*/
template<class Allocator>
template<class Body, class Allocator>
void
accept(http::header<true, http::basic_fields<Allocator>> const& req);
accept(http::request<Body,
http::basic_fields<Allocator>> const& req);
/** Respond to a WebSocket HTTP Upgrade request
@@ -1040,9 +1041,10 @@ public:
@throws system_error Thrown on failure.
*/
template<class Allocator, class ResponseDecorator>
template<class Body, class Allocator,
class ResponseDecorator>
void
accept_ex(http::header<true,
accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator);
@@ -1074,10 +1076,11 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class Allocator>
template<class Body, class Allocator>
void
accept(http::header<true, http::basic_fields<Allocator>> const& req,
error_code& ec);
accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
error_code& ec);
/** Respond to a WebSocket HTTP Upgrade request
@@ -1116,9 +1119,10 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class Allocator, class ResponseDecorator>
template<class Body, class Allocator,
class ResponseDecorator>
void
accept_ex(http::header<true,
accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator,
error_code& ec);
@@ -1156,10 +1160,12 @@ public:
@throws system_error Thrown on failure.
*/
template<class Allocator, class ConstBufferSequence>
template<class Body, class Allocator,
class ConstBufferSequence>
void
accept(http::header<true, http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers);
accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers);
/** Respond to a WebSocket HTTP Upgrade request
@@ -1203,10 +1209,10 @@ public:
@throws system_error Thrown on failure.
*/
template<class Allocator, class ConstBufferSequence,
class ResponseDecorator>
template<class Body, class Allocator,
class ConstBufferSequence, class ResponseDecorator>
void
accept_ex(http::header<true,
accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator);
@@ -1244,10 +1250,13 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class Allocator, class ConstBufferSequence>
template<class Body, class Allocator,
class ConstBufferSequence>
void
accept(http::header<true, Allocator> const& req,
ConstBufferSequence const& buffers, error_code& ec);
accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
error_code& ec);
/** Respond to a WebSocket HTTP Upgrade request
@@ -1291,10 +1300,10 @@ public:
@param ec Set to indicate what error occurred, if any.
*/
template<class Allocator, class ConstBufferSequence,
class ResponseDecorator>
template<class Body, class Allocator,
class ConstBufferSequence, class ResponseDecorator>
void
accept_ex(http::header<true,
accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
@@ -1580,14 +1589,15 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class Allocator, class AcceptHandler>
template<class Body, class Allocator,
class AcceptHandler>
#if BEAST_DOXYGEN
void_or_deduced
#else
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept(http::header<true,
async_accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
AcceptHandler&& handler);
@@ -1645,7 +1655,7 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class Allocator,
template<class Body, class Allocator,
class ResponseDecorator, class AcceptHandler>
#if BEAST_DOXYGEN
void_or_deduced
@@ -1653,7 +1663,7 @@ public:
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept_ex(http::header<true,
async_accept_ex(http::request<Body,
http::basic_fields<Allocator>> const& req,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
@@ -1710,7 +1720,7 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class Allocator,
template<class Body, class Allocator,
class ConstBufferSequence, class AcceptHandler>
#if BEAST_DOXYGEN
void_or_deduced
@@ -1718,7 +1728,7 @@ public:
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept(http::header<true,
async_accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
AcceptHandler&& handler);
@@ -1784,19 +1794,23 @@ public:
this function. Invocation of the handler will be performed in a
manner equivalent to using `boost::asio::io_service::post`.
*/
template<class Allocator, class ConstBufferSequence,
class ResponseDecorator, class AcceptHandler>
template<
class Body, class Allocator,
class ConstBufferSequence,
class ResponseDecorator,
class AcceptHandler>
#if BEAST_DOXYGEN
void_or_deduced
#else
async_return_type<
AcceptHandler, void(error_code)>
#endif
async_accept_ex(http::header<true,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
async_accept_ex(
http::request<Body,
http::basic_fields<Allocator>> const& req,
ConstBufferSequence const& buffers,
ResponseDecorator const& decorator,
AcceptHandler&& handler);
/** Send an HTTP WebSocket Upgrade request and receive the response.
@@ -3326,9 +3340,10 @@ private:
string_view target,
Decorator const& decorator);
template<class Allocator, class Decorator>
template<class Body,
class Allocator, class Decorator>
response_type
build_response(http::header<true,
build_response(http::request<Body,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator);
@@ -3337,22 +3352,22 @@ private:
do_accept(Decorator const& decorator,
error_code& ec);
template<class Allocator, class Decorator>
template<class Body, class Allocator,
class Decorator>
void
do_accept(http::header<true,
do_accept(http::request<Body,
http::basic_fields<Allocator>> const& req,
Decorator const& decorator, error_code& ec);
template<class RequestDecorator>
void
do_handshake(response_type* res_p,
string_view host,
string_view target,
RequestDecorator const& decorator,
error_code& ec);
string_view host, string_view target,
RequestDecorator const& decorator,
error_code& ec);
void
do_response(http::header<false> const& resp,
do_response(response_type const& resp,
detail::sec_ws_key_type const& key, error_code& ec);
};

View File

@@ -138,19 +138,18 @@ public:
ws.accept(buffers);
}
template<class NextLayer, class Fields>
template<class NextLayer>
void
accept(stream<NextLayer>& ws,
http::header<true, Fields> const& req) const
http::request<http::empty_body> const& req) const
{
ws.accept(req);
}
template<class NextLayer,
class Fields, class Buffers>
template<class NextLayer, class Buffers>
void
accept(stream<NextLayer>& ws,
http::header<true, Fields> const& req,
http::request<http::empty_body> const& req,
Buffers const& buffers) const
{
ws.accept(req, buffers);
@@ -175,22 +174,20 @@ public:
ws.accept_ex(buffers, d);
}
template<class NextLayer,
class Fields, class Decorator>
template<class NextLayer, class Decorator>
void
accept_ex(stream<NextLayer>& ws,
http::header<true, Fields> const& req,
http::request<http::empty_body> const& req,
Decorator const& d) const
{
ws.accept_ex(req, d);
}
template<class NextLayer,
class Fields, class Buffers,
class Decorator>
class Buffers, class Decorator>
void
accept_ex(stream<NextLayer>& ws,
http::header<true, Fields> const& req,
http::request<http::empty_body> const& req,
Buffers const& buffers,
Decorator const& d) const
{
@@ -332,10 +329,10 @@ public:
throw system_error{ec};
}
template<class NextLayer, class Fields>
template<class NextLayer>
void
accept(stream<NextLayer>& ws,
http::header<true, Fields> const& req) const
http::request<http::empty_body> const& req) const
{
error_code ec;
ws.async_accept(req, yield_[ec]);
@@ -343,11 +340,10 @@ public:
throw system_error{ec};
}
template<class NextLayer,
class Fields, class Buffers>
template<class NextLayer, class Buffers>
void
accept(stream<NextLayer>& ws,
http::header<true, Fields> const& req,
http::request<http::empty_body> const& req,
Buffers const& buffers) const
{
error_code ec;
@@ -382,11 +378,10 @@ public:
throw system_error{ec};
}
template<class NextLayer,
class Fields, class Decorator>
template<class NextLayer, class Decorator>
void
accept_ex(stream<NextLayer>& ws,
http::header<true, Fields> const& req,
http::request<http::empty_body> const& req,
Decorator const& d) const
{
error_code ec;
@@ -395,11 +390,11 @@ public:
throw system_error{ec};
}
template<class NextLayer, class Fields,
template<class NextLayer,
class Buffers, class Decorator>
void
accept_ex(stream<NextLayer>& ws,
http::header<true, Fields> const& req,
http::request<http::empty_body> const& req,
Buffers const& buffers,
Decorator const& d) const
{