2016-10-24 08:12:09 -04:00
|
|
|
//
|
2017-07-24 09:42:36 -07:00
|
|
|
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2016-10-24 08:12:09 -04:00
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
//
|
2017-07-20 13:40:34 -07:00
|
|
|
// Official repository: https://github.com/boostorg/beast
|
|
|
|
//
|
2016-10-24 08:12:09 -04:00
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
#ifndef BOOST_BEAST_WEBSOCKET_IMPL_WRITE_IPP
|
|
|
|
#define BOOST_BEAST_WEBSOCKET_IMPL_WRITE_IPP
|
|
|
|
|
|
|
|
#include <boost/beast/core/bind_handler.hpp>
|
|
|
|
#include <boost/beast/core/buffer_cat.hpp>
|
|
|
|
#include <boost/beast/core/buffer_prefix.hpp>
|
|
|
|
#include <boost/beast/core/consuming_buffers.hpp>
|
|
|
|
#include <boost/beast/core/handler_ptr.hpp>
|
|
|
|
#include <boost/beast/core/flat_static_buffer.hpp>
|
|
|
|
#include <boost/beast/core/type_traits.hpp>
|
|
|
|
#include <boost/beast/core/detail/clamp.hpp>
|
|
|
|
#include <boost/beast/core/detail/config.hpp>
|
|
|
|
#include <boost/beast/websocket/detail/frame.hpp>
|
2017-08-12 20:50:23 -07:00
|
|
|
#include <boost/asio/coroutine.hpp>
|
2017-05-14 09:25:43 -07:00
|
|
|
#include <boost/asio/handler_alloc_hook.hpp>
|
|
|
|
#include <boost/asio/handler_continuation_hook.hpp>
|
|
|
|
#include <boost/asio/handler_invoke_hook.hpp>
|
2016-10-24 08:12:09 -04:00
|
|
|
#include <boost/assert.hpp>
|
2017-06-08 05:54:47 -07:00
|
|
|
#include <boost/config.hpp>
|
2017-05-22 15:30:12 -07:00
|
|
|
#include <boost/throw_exception.hpp>
|
2016-10-24 08:12:09 -04:00
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
|
|
|
|
2017-07-20 13:40:34 -07:00
|
|
|
namespace boost {
|
2016-10-24 08:12:09 -04:00
|
|
|
namespace beast {
|
|
|
|
namespace websocket {
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
template<class Buffers, class Handler>
|
2017-07-15 17:05:24 -07:00
|
|
|
class stream<NextLayer>::write_some_op
|
2017-08-12 20:50:23 -07:00
|
|
|
: public boost::asio::coroutine
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
Handler h_;
|
|
|
|
stream<NextLayer>& ws_;
|
|
|
|
consuming_buffers<Buffers> cb_;
|
|
|
|
detail::frame_header fh_;
|
|
|
|
detail::prepared_key key_;
|
|
|
|
std::size_t remain_;
|
|
|
|
token tok_;
|
|
|
|
int how_;
|
|
|
|
bool fin_;
|
|
|
|
bool more_;
|
2016-10-24 08:12:09 -04:00
|
|
|
|
|
|
|
public:
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some_op(write_some_op&&) = default;
|
|
|
|
write_some_op(write_some_op const&) = default;
|
2016-10-24 08:12:09 -04:00
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
template<class DeducedHandler>
|
|
|
|
write_some_op(
|
|
|
|
DeducedHandler&& h,
|
|
|
|
stream<NextLayer>& ws,
|
|
|
|
bool fin,
|
|
|
|
Buffers const& bs)
|
|
|
|
: h_(std::forward<DeducedHandler>(h))
|
|
|
|
, ws_(ws)
|
|
|
|
, cb_(bs)
|
|
|
|
, tok_(ws_.t_.unique())
|
|
|
|
, fin_(fin)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
Handler&
|
|
|
|
handler()
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
return h_;
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
void operator()(
|
|
|
|
error_code ec,
|
2017-06-29 11:36:14 -07:00
|
|
|
std::size_t bytes_transferred,
|
2017-08-12 20:50:23 -07:00
|
|
|
bool)
|
|
|
|
{
|
|
|
|
(*this)(ec, bytes_transferred);
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator()(
|
|
|
|
error_code ec = {},
|
|
|
|
std::size_t bytes_transferred = 0);
|
2016-10-24 08:12:09 -04:00
|
|
|
|
|
|
|
friend
|
|
|
|
void* asio_handler_allocate(
|
2017-07-15 17:05:24 -07:00
|
|
|
std::size_t size, write_some_op* op)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-05-14 09:25:43 -07:00
|
|
|
using boost::asio::asio_handler_allocate;
|
|
|
|
return asio_handler_allocate(
|
2017-08-12 20:50:23 -07:00
|
|
|
size, std::addressof(op->h_));
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
friend
|
|
|
|
void asio_handler_deallocate(
|
2017-07-15 17:05:24 -07:00
|
|
|
void* p, std::size_t size, write_some_op* op)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-05-14 09:25:43 -07:00
|
|
|
using boost::asio::asio_handler_deallocate;
|
|
|
|
asio_handler_deallocate(
|
2017-08-12 20:50:23 -07:00
|
|
|
p, size, std::addressof(op->h_));
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
friend
|
2017-07-15 17:05:24 -07:00
|
|
|
bool asio_handler_is_continuation(write_some_op* op)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
using boost::asio::asio_handler_is_continuation;
|
|
|
|
return asio_handler_is_continuation(
|
|
|
|
std::addressof(op->h_));
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class Function>
|
|
|
|
friend
|
2017-07-15 17:05:24 -07:00
|
|
|
void asio_handler_invoke(Function&& f, write_some_op* op)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-05-14 09:25:43 -07:00
|
|
|
using boost::asio::asio_handler_invoke;
|
|
|
|
asio_handler_invoke(
|
2017-08-12 20:50:23 -07:00
|
|
|
f, std::addressof(op->h_));
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
template<class Buffers, class Handler>
|
|
|
|
void
|
|
|
|
stream<NextLayer>::
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some_op<Buffers, Handler>::
|
2016-10-24 18:41:25 -04:00
|
|
|
operator()(error_code ec,
|
2017-08-12 20:50:23 -07:00
|
|
|
std::size_t bytes_transferred)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2016-10-24 20:02:38 -04:00
|
|
|
using beast::detail::clamp;
|
2016-10-24 18:41:25 -04:00
|
|
|
using boost::asio::buffer;
|
2016-10-24 08:12:09 -04:00
|
|
|
using boost::asio::buffer_copy;
|
2016-10-24 18:41:25 -04:00
|
|
|
using boost::asio::buffer_size;
|
2017-08-12 20:50:23 -07:00
|
|
|
using boost::asio::mutable_buffers_1;
|
2016-10-24 18:41:25 -04:00
|
|
|
enum
|
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
do_nomask_nofrag,
|
|
|
|
do_nomask_frag,
|
|
|
|
do_mask_nofrag,
|
|
|
|
do_mask_frag,
|
|
|
|
do_deflate
|
2016-10-24 18:41:25 -04:00
|
|
|
};
|
2017-08-12 20:50:23 -07:00
|
|
|
std::size_t n;
|
|
|
|
boost::asio::mutable_buffer b;
|
|
|
|
|
|
|
|
BOOST_ASIO_CORO_REENTER(*this)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
// Set up the outgoing frame header
|
|
|
|
if(! ws_.wr_.cont)
|
2017-06-29 11:36:14 -07:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
ws_.wr_begin();
|
|
|
|
fh_.rsv1 = ws_.wr_.compress;
|
2017-06-29 11:36:14 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
fh_.rsv1 = false;
|
2017-06-29 11:36:14 -07:00
|
|
|
}
|
2017-08-12 20:50:23 -07:00
|
|
|
fh_.rsv2 = false;
|
|
|
|
fh_.rsv3 = false;
|
|
|
|
fh_.op = ws_.wr_.cont ?
|
|
|
|
detail::opcode::cont : ws_.wr_opcode_;
|
|
|
|
fh_.mask =
|
|
|
|
ws_.role_ == role_type::client;
|
|
|
|
|
|
|
|
// Choose a write algorithm
|
|
|
|
if(ws_.wr_.compress)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
how_ = do_deflate;
|
2017-06-29 11:36:14 -07:00
|
|
|
}
|
2017-08-12 20:50:23 -07:00
|
|
|
else if(! fh_.mask)
|
2017-06-29 11:36:14 -07:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
if(! ws_.wr_.autofrag)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
how_ = do_nomask_nofrag;
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
2016-10-24 18:41:25 -04:00
|
|
|
else
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
BOOST_ASSERT(ws_.wr_.buf_size != 0);
|
|
|
|
remain_ = buffer_size(cb_);
|
|
|
|
if(remain_ > ws_.wr_.buf_size)
|
|
|
|
how_ = do_nomask_frag;
|
2017-06-29 11:36:14 -07:00
|
|
|
else
|
2017-08-12 20:50:23 -07:00
|
|
|
how_ = do_nomask_nofrag;
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
2017-06-29 11:36:14 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
if(! ws_.wr_.autofrag)
|
2016-10-24 18:41:25 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
how_ = do_mask_nofrag;
|
2016-10-24 18:41:25 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
BOOST_ASSERT(ws_.wr_.buf_size != 0);
|
|
|
|
remain_ = buffer_size(cb_);
|
|
|
|
if(remain_ > ws_.wr_.buf_size)
|
|
|
|
how_ = do_mask_frag;
|
2016-10-24 18:41:25 -04:00
|
|
|
else
|
2017-08-12 20:50:23 -07:00
|
|
|
how_ = do_mask_nofrag;
|
2016-10-24 18:41:25 -04:00
|
|
|
}
|
2017-06-29 11:36:14 -07:00
|
|
|
}
|
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
do_maybe_suspend:
|
|
|
|
// Maybe suspend
|
|
|
|
if(! ws_.wr_block_)
|
2017-06-29 11:36:14 -07:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
// Acquire the write block
|
|
|
|
ws_.wr_block_ = tok_;
|
2016-10-24 18:41:25 -04:00
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
// Make sure the stream is open
|
|
|
|
if(ws_.failed_)
|
|
|
|
{
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
ws_.get_io_service().post(
|
|
|
|
bind_handler(std::move(*this),
|
|
|
|
boost::asio::error::operation_aborted));
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-10-24 18:41:25 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
// Suspend
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ != tok_);
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
ws_.wr_op_.save(std::move(*this));
|
|
|
|
|
|
|
|
// Acquire the write block
|
|
|
|
BOOST_ASSERT(! ws_.wr_block_);
|
|
|
|
ws_.wr_block_ = tok_;
|
|
|
|
|
|
|
|
// Resume
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
ws_.get_io_service().post(std::move(*this));
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
|
|
|
|
// Make sure the stream is open
|
|
|
|
if(ws_.failed_)
|
|
|
|
{
|
|
|
|
ec = boost::asio::error::operation_aborted;
|
|
|
|
goto upcall;
|
|
|
|
}
|
2016-10-24 18:41:25 -04:00
|
|
|
}
|
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
//------------------------------------------------------------------
|
2016-10-24 18:41:25 -04:00
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
if(how_ == do_nomask_nofrag)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
fh_.fin = fin_;
|
|
|
|
fh_.len = buffer_size(cb_);
|
|
|
|
ws_.wr_.fb.reset();
|
|
|
|
detail::write<flat_static_buffer_base>(
|
|
|
|
ws_.wr_.fb, fh_);
|
|
|
|
ws_.wr_.cont = ! fin_;
|
|
|
|
// Send frame
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
boost::asio::async_write(ws_.stream_,
|
|
|
|
buffer_cat(ws_.wr_.fb.data(), cb_),
|
|
|
|
std::move(*this));
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
if(ec)
|
|
|
|
ws_.failed_ = true;
|
|
|
|
goto upcall;
|
2016-10-24 18:41:25 -04:00
|
|
|
}
|
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
else if(how_ == do_nomask_frag)
|
2016-10-24 18:41:25 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
fh_.len = clamp(remain_, ws_.wr_.buf_size);
|
|
|
|
remain_ -= clamp(fh_.len);
|
|
|
|
fh_.fin = fin_ ? remain_ == 0 : false;
|
|
|
|
ws_.wr_.fb.reset();
|
|
|
|
detail::write<flat_static_buffer_base>(
|
|
|
|
ws_.wr_.fb, fh_);
|
|
|
|
ws_.wr_.cont = ! fin_;
|
|
|
|
// Send frame
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
boost::asio::async_write(
|
|
|
|
ws_.stream_, buffer_cat(
|
|
|
|
ws_.wr_.fb.data(), buffer_prefix(
|
|
|
|
clamp(fh_.len), cb_)),
|
|
|
|
std::move(*this));
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
if(ec)
|
|
|
|
{
|
|
|
|
ws_.failed_ = true;
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
if(remain_ == 0)
|
|
|
|
goto upcall;
|
|
|
|
cb_.consume(
|
|
|
|
bytes_transferred - ws_.wr_.fb.size());
|
|
|
|
fh_.op = detail::opcode::cont;
|
|
|
|
// Allow outgoing control frames to
|
|
|
|
// be sent in between message frames
|
|
|
|
ws_.wr_block_.reset();
|
|
|
|
if( ws_.close_op_.maybe_invoke() ||
|
|
|
|
ws_.rd_op_.maybe_invoke() ||
|
|
|
|
ws_.ping_op_.maybe_invoke())
|
|
|
|
{
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
ws_.get_io_service().post(
|
|
|
|
std::move(*this));
|
|
|
|
goto do_maybe_suspend;
|
|
|
|
}
|
|
|
|
ws_.wr_block_ = tok_;
|
|
|
|
}
|
2016-10-24 18:41:25 -04:00
|
|
|
}
|
2017-08-12 20:50:23 -07:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
else if(how_ == do_mask_nofrag)
|
2016-10-24 18:41:25 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
remain_ = buffer_size(cb_);
|
|
|
|
fh_.fin = fin_;
|
|
|
|
fh_.len = remain_;
|
|
|
|
fh_.key = ws_.maskgen_();
|
|
|
|
detail::prepare_key(key_, fh_.key);
|
|
|
|
ws_.wr_.fb.reset();
|
|
|
|
detail::write<flat_static_buffer_base>(
|
|
|
|
ws_.wr_.fb, fh_);
|
|
|
|
n = clamp(remain_, ws_.wr_.buf_size);
|
|
|
|
buffer_copy(buffer(
|
|
|
|
ws_.wr_.buf.get(), n), cb_);
|
|
|
|
detail::mask_inplace(buffer(
|
|
|
|
ws_.wr_.buf.get(), n), key_);
|
|
|
|
remain_ -= n;
|
|
|
|
ws_.wr_.cont = ! fin_;
|
|
|
|
// Send frame header and partial payload
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
boost::asio::async_write(
|
|
|
|
ws_.stream_, buffer_cat(ws_.wr_.fb.data(),
|
|
|
|
buffer(ws_.wr_.buf.get(), n)),
|
|
|
|
std::move(*this));
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
if(ec)
|
|
|
|
{
|
|
|
|
ws_.failed_ = true;
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
while(remain_ > 0)
|
|
|
|
{
|
|
|
|
cb_.consume(ws_.wr_.buf_size);
|
|
|
|
n = clamp(remain_, ws_.wr_.buf_size);
|
|
|
|
buffer_copy(buffer(
|
|
|
|
ws_.wr_.buf.get(), n), cb_);
|
|
|
|
detail::mask_inplace(buffer(
|
|
|
|
ws_.wr_.buf.get(), n), key_);
|
|
|
|
remain_ -= n;
|
|
|
|
// Send partial payload
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
boost::asio::async_write(ws_.stream_,
|
|
|
|
buffer(ws_.wr_.buf.get(), n),
|
|
|
|
std::move(*this));
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
if(ec)
|
|
|
|
{
|
|
|
|
ws_.failed_ = true;
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto upcall;
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
2017-08-12 20:50:23 -07:00
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
else if(how_ == do_mask_frag)
|
2016-10-24 18:41:25 -04:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
n = clamp(remain_, ws_.wr_.buf_size);
|
|
|
|
remain_ -= n;
|
|
|
|
fh_.len = n;
|
|
|
|
fh_.key = ws_.maskgen_();
|
|
|
|
fh_.fin = fin_ ? remain_ == 0 : false;
|
|
|
|
detail::prepare_key(key_, fh_.key);
|
|
|
|
buffer_copy(buffer(
|
|
|
|
ws_.wr_.buf.get(), n), cb_);
|
|
|
|
detail::mask_inplace(buffer(
|
|
|
|
ws_.wr_.buf.get(), n), key_);
|
|
|
|
ws_.wr_.fb.reset();
|
|
|
|
detail::write<flat_static_buffer_base>(
|
|
|
|
ws_.wr_.fb, fh_);
|
|
|
|
ws_.wr_.cont = ! fin_;
|
|
|
|
// Send frame
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
boost::asio::async_write(ws_.stream_,
|
|
|
|
buffer_cat(ws_.wr_.fb.data(),
|
|
|
|
buffer(ws_.wr_.buf.get(), n)),
|
|
|
|
std::move(*this));
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
if(ec)
|
|
|
|
{
|
|
|
|
ws_.failed_ = true;
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
if(remain_ == 0)
|
|
|
|
goto upcall;
|
|
|
|
cb_.consume(
|
|
|
|
bytes_transferred - ws_.wr_.fb.size());
|
|
|
|
fh_.op = detail::opcode::cont;
|
|
|
|
// Allow outgoing control frames to
|
|
|
|
// be sent in between message frames:
|
|
|
|
ws_.wr_block_.reset();
|
|
|
|
if( ws_.close_op_.maybe_invoke() ||
|
|
|
|
ws_.rd_op_.maybe_invoke() ||
|
|
|
|
ws_.ping_op_.maybe_invoke())
|
|
|
|
{
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
ws_.get_io_service().post(
|
|
|
|
std::move(*this));
|
|
|
|
goto do_maybe_suspend;
|
|
|
|
}
|
|
|
|
ws_.wr_block_ = tok_;
|
|
|
|
}
|
2016-10-24 18:41:25 -04:00
|
|
|
}
|
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
|
|
else if(how_ == do_deflate)
|
2017-06-29 11:36:14 -07:00
|
|
|
{
|
2017-08-12 20:50:23 -07:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
b = buffer(ws_.wr_.buf.get(),
|
|
|
|
ws_.wr_.buf_size);
|
|
|
|
more_ = detail::deflate(
|
|
|
|
ws_.pmd_->zo, b, cb_, fin_, ec);
|
|
|
|
ws_.failed_ = !!ec;
|
|
|
|
if(ws_.failed_)
|
|
|
|
{
|
|
|
|
// Always dispatching is easiest
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
ws_.get_io_service().post(
|
|
|
|
bind_handler(std::move(*this), ec));
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
n = buffer_size(b);
|
|
|
|
if(n == 0)
|
|
|
|
{
|
|
|
|
// The input was consumed, but there
|
|
|
|
// is no output due to compression
|
|
|
|
// latency.
|
|
|
|
BOOST_ASSERT(! fin_);
|
|
|
|
BOOST_ASSERT(buffer_size(cb_) == 0);
|
|
|
|
|
|
|
|
// We can skip the dispatch if the
|
|
|
|
// asynchronous initiation function is
|
|
|
|
// not on call stack but its hard to
|
|
|
|
// figure out so be safe and dispatch.
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
ws_.get_io_service().post(
|
|
|
|
std::move(*this));
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
if(fh_.mask)
|
|
|
|
{
|
|
|
|
fh_.key = ws_.maskgen_();
|
|
|
|
detail::prepared_key key;
|
|
|
|
detail::prepare_key(key, fh_.key);
|
|
|
|
detail::mask_inplace(b, key);
|
|
|
|
}
|
|
|
|
fh_.fin = ! more_;
|
|
|
|
fh_.len = n;
|
|
|
|
ws_.wr_.fb.reset();
|
|
|
|
detail::write<
|
|
|
|
flat_static_buffer_base>(ws_.wr_.fb, fh_);
|
|
|
|
ws_.wr_.cont = ! fin_;
|
|
|
|
// Send frame
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
boost::asio::async_write(ws_.stream_,
|
|
|
|
buffer_cat(ws_.wr_.fb.data(),
|
|
|
|
mutable_buffers_1{b}), std::move(*this));
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
if(ec)
|
|
|
|
{
|
|
|
|
ws_.failed_ = true;
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
if(more_)
|
|
|
|
{
|
|
|
|
fh_.op = detail::opcode::cont;
|
|
|
|
fh_.rsv1 = false;
|
|
|
|
// Allow outgoing control frames to
|
|
|
|
// be sent in between message frames:
|
|
|
|
ws_.wr_block_.reset();
|
|
|
|
if( ws_.close_op_.maybe_invoke() ||
|
|
|
|
ws_.rd_op_.maybe_invoke() ||
|
|
|
|
ws_.ping_op_.maybe_invoke())
|
|
|
|
{
|
|
|
|
BOOST_ASIO_CORO_YIELD
|
|
|
|
ws_.get_io_service().post(
|
|
|
|
std::move(*this));
|
|
|
|
goto do_maybe_suspend;
|
|
|
|
}
|
|
|
|
ws_.wr_block_ = tok_;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
if(fh_.fin && (
|
|
|
|
(ws_.role_ == role_type::client &&
|
|
|
|
ws_.pmd_config_.client_no_context_takeover) ||
|
|
|
|
(ws_.role_ == role_type::server &&
|
|
|
|
ws_.pmd_config_.server_no_context_takeover)))
|
|
|
|
ws_.pmd_->zo.reset();
|
|
|
|
goto upcall;
|
|
|
|
}
|
|
|
|
}
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
2017-06-29 11:36:14 -07:00
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
//--------------------------------------------------------------------------
|
2017-06-29 11:36:14 -07:00
|
|
|
|
2017-08-12 20:50:23 -07:00
|
|
|
upcall:
|
2017-08-13 06:48:38 -07:00
|
|
|
BOOST_ASSERT(ws_.wr_block_ == tok_);
|
|
|
|
ws_.wr_block_.reset();
|
2017-08-12 20:50:23 -07:00
|
|
|
ws_.close_op_.maybe_invoke() ||
|
|
|
|
ws_.rd_op_.maybe_invoke() ||
|
|
|
|
ws_.ping_op_.maybe_invoke();
|
|
|
|
h_(ec);
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-20 21:28:17 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-10-24 08:12:09 -04:00
|
|
|
template<class NextLayer>
|
|
|
|
template<class ConstBufferSequence>
|
|
|
|
void
|
|
|
|
stream<NextLayer>::
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some(bool fin, ConstBufferSequence const& buffers)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-05-10 12:03:00 -07:00
|
|
|
static_assert(is_sync_stream<next_layer_type>::value,
|
2016-10-24 08:12:09 -04:00
|
|
|
"SyncStream requirements not met");
|
2017-05-06 12:36:40 -07:00
|
|
|
static_assert(beast::is_const_buffer_sequence<
|
2016-10-24 08:12:09 -04:00
|
|
|
ConstBufferSequence>::value,
|
|
|
|
"ConstBufferSequence requirements not met");
|
|
|
|
error_code ec;
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some(fin, buffers, ec);
|
2016-10-24 08:12:09 -04:00
|
|
|
if(ec)
|
2017-05-22 15:30:12 -07:00
|
|
|
BOOST_THROW_EXCEPTION(system_error{ec});
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
template<class ConstBufferSequence>
|
|
|
|
void
|
|
|
|
stream<NextLayer>::
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some(bool fin,
|
2016-10-24 08:12:09 -04:00
|
|
|
ConstBufferSequence const& buffers, error_code& ec)
|
|
|
|
{
|
2017-05-10 12:03:00 -07:00
|
|
|
static_assert(is_sync_stream<next_layer_type>::value,
|
2016-10-24 08:12:09 -04:00
|
|
|
"SyncStream requirements not met");
|
2017-05-06 12:36:40 -07:00
|
|
|
static_assert(beast::is_const_buffer_sequence<
|
2016-10-24 08:12:09 -04:00
|
|
|
ConstBufferSequence>::value,
|
|
|
|
"ConstBufferSequence requirements not met");
|
2016-10-24 20:02:38 -04:00
|
|
|
using beast::detail::clamp;
|
2016-10-24 08:12:09 -04:00
|
|
|
using boost::asio::buffer;
|
|
|
|
using boost::asio::buffer_copy;
|
|
|
|
using boost::asio::buffer_size;
|
2017-08-12 20:50:23 -07:00
|
|
|
// Make sure the stream is open
|
|
|
|
if(failed_)
|
|
|
|
{
|
|
|
|
ec = boost::asio::error::operation_aborted;
|
|
|
|
return;
|
|
|
|
}
|
2016-10-24 08:12:09 -04:00
|
|
|
detail::frame_header fh;
|
2016-10-24 18:41:25 -04:00
|
|
|
if(! wr_.cont)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2016-10-24 18:41:25 -04:00
|
|
|
wr_begin();
|
|
|
|
fh.rsv1 = wr_.compress;
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
2016-10-24 18:41:25 -04:00
|
|
|
else
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2016-10-24 18:41:25 -04:00
|
|
|
fh.rsv1 = false;
|
2016-10-24 11:18:31 -04:00
|
|
|
}
|
2016-10-24 18:41:25 -04:00
|
|
|
fh.rsv2 = false;
|
|
|
|
fh.rsv3 = false;
|
2017-06-08 21:01:35 -07:00
|
|
|
fh.op = wr_.cont ?
|
|
|
|
detail::opcode::cont : wr_opcode_;
|
2017-06-24 10:13:17 -07:00
|
|
|
fh.mask = role_ == role_type::client;
|
2016-10-24 18:41:25 -04:00
|
|
|
auto remain = buffer_size(buffers);
|
|
|
|
if(wr_.compress)
|
2016-10-24 11:18:31 -04:00
|
|
|
{
|
|
|
|
consuming_buffers<
|
2016-10-24 18:41:25 -04:00
|
|
|
ConstBufferSequence> cb{buffers};
|
2016-10-24 11:18:31 -04:00
|
|
|
for(;;)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2016-10-24 18:41:25 -04:00
|
|
|
auto b = buffer(
|
|
|
|
wr_.buf.get(), wr_.buf_size);
|
|
|
|
auto const more = detail::deflate(
|
|
|
|
pmd_->zo, b, cb, fin, ec);
|
2017-06-19 16:58:23 -07:00
|
|
|
failed_ = !!ec;
|
2016-10-24 18:41:25 -04:00
|
|
|
if(failed_)
|
|
|
|
return;
|
|
|
|
auto const n = buffer_size(b);
|
|
|
|
if(n == 0)
|
|
|
|
{
|
|
|
|
// The input was consumed, but there
|
|
|
|
// is no output due to compression
|
|
|
|
// latency.
|
|
|
|
BOOST_ASSERT(! fin);
|
|
|
|
BOOST_ASSERT(buffer_size(cb) == 0);
|
|
|
|
fh.fin = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(fh.mask)
|
|
|
|
{
|
|
|
|
fh.key = maskgen_();
|
|
|
|
detail::prepared_key key;
|
|
|
|
detail::prepare_key(key, fh.key);
|
|
|
|
detail::mask_inplace(b, key);
|
|
|
|
}
|
|
|
|
fh.fin = ! more;
|
2016-10-24 11:18:31 -04:00
|
|
|
fh.len = n;
|
2016-10-24 08:12:09 -04:00
|
|
|
detail::fh_streambuf fh_buf;
|
2017-07-14 20:25:39 -07:00
|
|
|
detail::write<flat_static_buffer_base>(fh_buf, fh);
|
2016-10-24 18:41:25 -04:00
|
|
|
wr_.cont = ! fin;
|
2016-10-24 08:12:09 -04:00
|
|
|
boost::asio::write(stream_,
|
2016-10-24 18:41:25 -04:00
|
|
|
buffer_cat(fh_buf.data(), b), ec);
|
2017-06-19 16:58:23 -07:00
|
|
|
failed_ = !!ec;
|
2016-10-24 08:12:09 -04:00
|
|
|
if(failed_)
|
|
|
|
return;
|
2016-10-24 18:41:25 -04:00
|
|
|
if(! more)
|
2016-10-24 11:18:31 -04:00
|
|
|
break;
|
2017-06-08 21:01:35 -07:00
|
|
|
fh.op = detail::opcode::cont;
|
2016-10-24 18:41:25 -04:00
|
|
|
fh.rsv1 = false;
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
2016-10-24 18:41:25 -04:00
|
|
|
if(fh.fin && (
|
2017-06-24 10:13:17 -07:00
|
|
|
(role_ == role_type::client &&
|
2016-10-24 18:41:25 -04:00
|
|
|
pmd_config_.client_no_context_takeover) ||
|
2017-06-24 10:13:17 -07:00
|
|
|
(role_ == role_type::server &&
|
2016-10-24 18:41:25 -04:00
|
|
|
pmd_config_.server_no_context_takeover)))
|
|
|
|
pmd_->zo.reset();
|
2016-10-24 08:12:09 -04:00
|
|
|
return;
|
|
|
|
}
|
2016-10-24 18:41:25 -04:00
|
|
|
if(! fh.mask)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2016-10-24 18:41:25 -04:00
|
|
|
if(! wr_.autofrag)
|
|
|
|
{
|
|
|
|
// no mask, no autofrag
|
|
|
|
fh.fin = fin;
|
|
|
|
fh.len = remain;
|
|
|
|
detail::fh_streambuf fh_buf;
|
2017-07-14 20:25:39 -07:00
|
|
|
detail::write<flat_static_buffer_base>(fh_buf, fh);
|
2016-10-24 18:41:25 -04:00
|
|
|
wr_.cont = ! fin;
|
|
|
|
boost::asio::write(stream_,
|
|
|
|
buffer_cat(fh_buf.data(), buffers), ec);
|
2017-06-19 16:58:23 -07:00
|
|
|
failed_ = !!ec;
|
2016-10-24 18:41:25 -04:00
|
|
|
if(failed_)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no mask, autofrag
|
|
|
|
BOOST_ASSERT(wr_.buf_size != 0);
|
|
|
|
consuming_buffers<
|
|
|
|
ConstBufferSequence> cb{buffers};
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
auto const n = clamp(remain, wr_.buf_size);
|
|
|
|
remain -= n;
|
|
|
|
fh.len = n;
|
|
|
|
fh.fin = fin ? remain == 0 : false;
|
|
|
|
detail::fh_streambuf fh_buf;
|
2017-07-14 20:25:39 -07:00
|
|
|
detail::write<flat_static_buffer_base>(fh_buf, fh);
|
2016-10-24 18:41:25 -04:00
|
|
|
wr_.cont = ! fin;
|
|
|
|
boost::asio::write(stream_,
|
|
|
|
buffer_cat(fh_buf.data(),
|
2017-05-14 08:23:37 -07:00
|
|
|
buffer_prefix(n, cb)), ec);
|
2017-06-19 16:58:23 -07:00
|
|
|
failed_ = !!ec;
|
2016-10-24 18:41:25 -04:00
|
|
|
if(failed_)
|
|
|
|
return;
|
|
|
|
if(remain == 0)
|
|
|
|
break;
|
2017-06-08 21:01:35 -07:00
|
|
|
fh.op = detail::opcode::cont;
|
2016-10-24 18:41:25 -04:00
|
|
|
cb.consume(n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(! wr_.autofrag)
|
|
|
|
{
|
|
|
|
// mask, no autofrag
|
2016-10-24 08:12:09 -04:00
|
|
|
fh.fin = fin;
|
|
|
|
fh.len = remain;
|
2016-10-24 18:41:25 -04:00
|
|
|
fh.key = maskgen_();
|
|
|
|
detail::prepared_key key;
|
|
|
|
detail::prepare_key(key, fh.key);
|
2016-10-24 08:12:09 -04:00
|
|
|
detail::fh_streambuf fh_buf;
|
2017-07-14 20:25:39 -07:00
|
|
|
detail::write<flat_static_buffer_base>(fh_buf, fh);
|
2016-10-24 11:18:31 -04:00
|
|
|
consuming_buffers<
|
2016-10-24 18:41:25 -04:00
|
|
|
ConstBufferSequence> cb{buffers};
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2016-10-24 18:41:25 -04:00
|
|
|
auto const n = clamp(remain, wr_.buf_size);
|
|
|
|
auto const b = buffer(wr_.buf.get(), n);
|
|
|
|
buffer_copy(b, cb);
|
2016-10-24 08:12:09 -04:00
|
|
|
cb.consume(n);
|
|
|
|
remain -= n;
|
2016-10-24 18:41:25 -04:00
|
|
|
detail::mask_inplace(b, key);
|
|
|
|
wr_.cont = ! fin;
|
2016-10-24 08:12:09 -04:00
|
|
|
boost::asio::write(stream_,
|
2016-10-24 18:41:25 -04:00
|
|
|
buffer_cat(fh_buf.data(), b), ec);
|
2017-06-19 16:58:23 -07:00
|
|
|
failed_ = !!ec;
|
2016-10-24 08:12:09 -04:00
|
|
|
if(failed_)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while(remain > 0)
|
|
|
|
{
|
2016-10-24 18:41:25 -04:00
|
|
|
auto const n = clamp(remain, wr_.buf_size);
|
|
|
|
auto const b = buffer(wr_.buf.get(), n);
|
|
|
|
buffer_copy(b, cb);
|
2016-10-24 08:12:09 -04:00
|
|
|
cb.consume(n);
|
|
|
|
remain -= n;
|
2016-10-24 18:41:25 -04:00
|
|
|
detail::mask_inplace(b, key);
|
|
|
|
boost::asio::write(stream_, b, ec);
|
2017-06-19 16:58:23 -07:00
|
|
|
failed_ = !!ec;
|
2016-10-24 08:12:09 -04:00
|
|
|
if(failed_)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
{
|
2016-10-24 18:41:25 -04:00
|
|
|
// mask, autofrag
|
|
|
|
BOOST_ASSERT(wr_.buf_size != 0);
|
2016-10-24 11:18:31 -04:00
|
|
|
consuming_buffers<
|
2016-10-24 18:41:25 -04:00
|
|
|
ConstBufferSequence> cb{buffers};
|
2016-10-24 11:18:31 -04:00
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
fh.key = maskgen_();
|
2016-10-24 18:41:25 -04:00
|
|
|
detail::prepared_key key;
|
2016-10-24 11:18:31 -04:00
|
|
|
detail::prepare_key(key, fh.key);
|
2016-10-24 18:41:25 -04:00
|
|
|
auto const n = clamp(remain, wr_.buf_size);
|
|
|
|
auto const b = buffer(wr_.buf.get(), n);
|
|
|
|
buffer_copy(b, cb);
|
|
|
|
detail::mask_inplace(b, key);
|
2016-10-24 11:18:31 -04:00
|
|
|
fh.len = n;
|
|
|
|
remain -= n;
|
|
|
|
fh.fin = fin ? remain == 0 : false;
|
2017-04-14 19:15:33 -07:00
|
|
|
wr_.cont = ! fh.fin;
|
2016-10-24 11:18:31 -04:00
|
|
|
detail::fh_streambuf fh_buf;
|
2017-07-14 20:25:39 -07:00
|
|
|
detail::write<flat_static_buffer_base>(fh_buf, fh);
|
2016-10-24 11:18:31 -04:00
|
|
|
boost::asio::write(stream_,
|
2016-10-24 18:41:25 -04:00
|
|
|
buffer_cat(fh_buf.data(), b), ec);
|
2017-06-19 16:58:23 -07:00
|
|
|
failed_ = !!ec;
|
2016-10-24 11:18:31 -04:00
|
|
|
if(failed_)
|
|
|
|
return;
|
|
|
|
if(remain == 0)
|
|
|
|
break;
|
2017-06-08 21:01:35 -07:00
|
|
|
fh.op = detail::opcode::cont;
|
2016-10-24 11:18:31 -04:00
|
|
|
cb.consume(n);
|
|
|
|
}
|
|
|
|
return;
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
template<class ConstBufferSequence, class WriteHandler>
|
2017-05-12 17:13:03 -07:00
|
|
|
async_return_type<
|
|
|
|
WriteHandler, void(error_code)>
|
2016-10-24 08:12:09 -04:00
|
|
|
stream<NextLayer>::
|
2017-07-15 17:05:24 -07:00
|
|
|
async_write_some(bool fin,
|
2017-06-20 21:28:17 -07:00
|
|
|
ConstBufferSequence const& bs, WriteHandler&& handler)
|
2016-10-24 08:12:09 -04:00
|
|
|
{
|
2017-05-10 12:03:00 -07:00
|
|
|
static_assert(is_async_stream<next_layer_type>::value,
|
2016-10-24 08:12:09 -04:00
|
|
|
"AsyncStream requirements not met");
|
2017-05-06 12:36:40 -07:00
|
|
|
static_assert(beast::is_const_buffer_sequence<
|
2016-10-24 08:12:09 -04:00
|
|
|
ConstBufferSequence>::value,
|
|
|
|
"ConstBufferSequence requirements not met");
|
2017-05-06 12:36:40 -07:00
|
|
|
async_completion<WriteHandler,
|
|
|
|
void(error_code)> init{handler};
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some_op<ConstBufferSequence, handler_type<
|
2017-06-20 21:28:17 -07:00
|
|
|
WriteHandler, void(error_code)>>{init.completion_handler,
|
2017-08-12 20:50:23 -07:00
|
|
|
*this, fin, bs}();
|
2017-05-06 12:36:40 -07:00
|
|
|
return init.result.get();
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
2017-06-20 21:28:17 -07:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2016-10-24 08:12:09 -04:00
|
|
|
template<class NextLayer>
|
|
|
|
template<class ConstBufferSequence>
|
|
|
|
void
|
|
|
|
stream<NextLayer>::
|
|
|
|
write(ConstBufferSequence const& buffers)
|
|
|
|
{
|
2017-05-10 12:03:00 -07:00
|
|
|
static_assert(is_sync_stream<next_layer_type>::value,
|
2016-10-24 08:12:09 -04:00
|
|
|
"SyncStream requirements not met");
|
2017-05-06 12:36:40 -07:00
|
|
|
static_assert(beast::is_const_buffer_sequence<
|
2016-10-24 08:12:09 -04:00
|
|
|
ConstBufferSequence>::value,
|
|
|
|
"ConstBufferSequence requirements not met");
|
|
|
|
error_code ec;
|
|
|
|
write(buffers, ec);
|
|
|
|
if(ec)
|
2017-05-22 15:30:12 -07:00
|
|
|
BOOST_THROW_EXCEPTION(system_error{ec});
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class NextLayer>
|
|
|
|
template<class ConstBufferSequence>
|
|
|
|
void
|
|
|
|
stream<NextLayer>::
|
|
|
|
write(ConstBufferSequence const& buffers, error_code& ec)
|
|
|
|
{
|
2017-05-10 12:03:00 -07:00
|
|
|
static_assert(is_sync_stream<next_layer_type>::value,
|
2016-10-24 08:12:09 -04:00
|
|
|
"SyncStream requirements not met");
|
2017-05-06 12:36:40 -07:00
|
|
|
static_assert(beast::is_const_buffer_sequence<
|
2016-10-24 08:12:09 -04:00
|
|
|
ConstBufferSequence>::value,
|
|
|
|
"ConstBufferSequence requirements not met");
|
2017-07-15 17:05:24 -07:00
|
|
|
write_some(true, buffers, ec);
|
2016-10-24 08:12:09 -04:00
|
|
|
}
|
|
|
|
|
2017-06-20 21:28:17 -07:00
|
|
|
template<class NextLayer>
|
|
|
|
template<class ConstBufferSequence, class WriteHandler>
|
|
|
|
async_return_type<
|
|
|
|
WriteHandler, void(error_code)>
|
|
|
|
stream<NextLayer>::
|
|
|
|
async_write(
|
|
|
|
ConstBufferSequence const& bs, WriteHandler&& handler)
|
|
|
|
{
|
|
|
|
static_assert(is_async_stream<next_layer_type>::value,
|
|
|
|
"AsyncStream requirements not met");
|
|
|
|
static_assert(beast::is_const_buffer_sequence<
|
|
|
|
ConstBufferSequence>::value,
|
|
|
|
"ConstBufferSequence requirements not met");
|
|
|
|
async_completion<WriteHandler,
|
|
|
|
void(error_code)> init{handler};
|
2017-08-12 15:56:08 -07:00
|
|
|
write_some_op<ConstBufferSequence, handler_type<
|
|
|
|
WriteHandler, void(error_code)>>{init.completion_handler,
|
2017-08-12 20:50:23 -07:00
|
|
|
*this, true, bs}();
|
2017-06-20 21:28:17 -07:00
|
|
|
return init.result.get();
|
|
|
|
}
|
|
|
|
|
2016-10-24 08:12:09 -04:00
|
|
|
} // websocket
|
|
|
|
} // beast
|
2017-07-20 13:40:34 -07:00
|
|
|
} // boost
|
2016-10-24 08:12:09 -04:00
|
|
|
|
|
|
|
#endif
|