websocket close fixes and tests

This commit is contained in:
Vinnie Falco committed 2017-08-23 14:34:13 -07:00
1 parent 7e815435f6
commit 96eff81cea
6 files changed
+341 -87

No files matched your search

+12 -5
View File
@@ -43,8 +43,9 @@ class stream<NextLayer>::close_op
struct state
{
stream<NextLayer>& ws;
token tok;
detail::frame_buffer fb;
error_code ev;
token tok;
state(
Handler&,
@@ -201,7 +202,7 @@ operator()(error_code ec, std::size_t bytes_transferred)
// Suspend
BOOST_ASSERT(d.ws.rd_block_ != d.tok);
BOOST_ASIO_CORO_YIELD
d.ws.rd_op_.emplace(std::move(*this));
d.ws.r_close_op_.emplace(std::move(*this));
// Acquire the read block
BOOST_ASSERT(! d.ws.rd_block_);
@@ -230,7 +231,10 @@ operator()(error_code ec, std::size_t bytes_transferred)
d.ws.rd_.fh, d.ws.rd_.buf, code))
{
if(code != close_code::none)
break;
{
d.ev = error::failed;
goto teardown;
}
BOOST_ASIO_CORO_YIELD
d.ws.stream_.async_read_some(
d.ws.rd_.buf.prepare(read_size(d.ws.rd_.buf,
@@ -259,10 +263,11 @@ operator()(error_code ec, std::size_t bytes_transferred)
if(code != close_code::none)
{
// Protocol error
goto upcall;
d.ev = error::failed;
goto teardown;
}
d.ws.rd_.buf.consume(clamp(d.ws.rd_.fh.len));
break;
goto teardown;
}
d.ws.rd_.buf.consume(clamp(d.ws.rd_.fh.len));
}
@@ -305,6 +310,8 @@ operator()(error_code ec, std::size_t bytes_transferred)
// http://stackoverflow.com/questions/25587403/boost-asio-ssl-async-shutdown-always-finishes-with-an-error
ec.assign(0, ec.category());
}
if(! ec)
ec = d.ev;
d.ws.failed_ = true;
upcall:
+43 -42
View File
@@ -128,46 +128,47 @@ operator()(error_code ec, std::size_t)
BOOST_ASIO_CORO_REENTER(*this)
{
// Maybe suspend
if(! d.ws.wr_block_)
{
// Acquire the write block
d.ws.wr_block_ = d.tok;
// Make sure the stream is open
if(d.ws.failed_)
{
BOOST_ASIO_CORO_YIELD
d.ws.get_io_service().post(
bind_handler(std::move(*this),
boost::asio::error::operation_aborted));
goto upcall;
}
}
else
{
// Suspend
BOOST_ASSERT(d.ws.wr_block_ != d.tok);
BOOST_ASIO_CORO_YIELD
d.ws.rd_op_.emplace(std::move(*this)); // VFALCO emplace to rd_op_
// Acquire the write block
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = d.tok;
// Resume
BOOST_ASIO_CORO_YIELD
d.ws.get_io_service().post(std::move(*this));
BOOST_ASSERT(d.ws.wr_block_ == d.tok);
// Make sure the stream is open
if(d.ws.failed_)
{
ec = boost::asio::error::operation_aborted;
goto upcall;
}
}
if(d.code != close_code::none && ! d.ws.wr_close_)
{
if(! d.ws.wr_block_)
{
// Acquire the write block
d.ws.wr_block_ = d.tok;
// Make sure the stream is open
if(d.ws.failed_)
{
BOOST_ASIO_CORO_YIELD
d.ws.get_io_service().post(
bind_handler(std::move(*this),
boost::asio::error::operation_aborted));
goto upcall;
}
}
else
{
// Suspend
BOOST_ASSERT(d.ws.wr_block_ != d.tok);
BOOST_ASIO_CORO_YIELD
d.ws.rd_op_.emplace(std::move(*this)); // VFALCO emplace to rd_op_
// Acquire the write block
BOOST_ASSERT(! d.ws.wr_block_);
d.ws.wr_block_ = d.tok;
// Resume
BOOST_ASIO_CORO_YIELD
d.ws.get_io_service().post(std::move(*this));
BOOST_ASSERT(d.ws.wr_block_ == d.tok);
// Make sure the stream is open
if(d.ws.failed_)
{
ec = boost::asio::error::operation_aborted;
goto upcall;
}
}
// Serialize close frame
d.ws.template write_close<
flat_static_buffer_base>(
@@ -184,12 +185,12 @@ operator()(error_code ec, std::size_t)
goto upcall;
}
// Teardown
BOOST_ASSERT(d.ws.wr_block_ == d.tok);
//BOOST_ASSERT(d.ws.wr_block_ == d.tok);
using beast::websocket::async_teardown;
BOOST_ASIO_CORO_YIELD
async_teardown(d.ws.role_,
d.ws.stream_, std::move(*this));
BOOST_ASSERT(d.ws.wr_block_ == d.tok);
//BOOST_ASSERT(d.ws.wr_block_ == d.tok);
if(ec == boost::asio::error::eof)
{
// Rationale:
@@ -200,8 +201,8 @@ operator()(error_code ec, std::size_t)
ec = d.ev;
d.ws.failed_ = true;
upcall:
BOOST_ASSERT(d.ws.wr_block_ == d.tok);
d.ws.wr_block_.reset();
if(d.ws.wr_block_ == d.tok)
d.ws.wr_block_.reset();
d_.invoke(ec);
}
}
+5 -2
View File
@@ -49,9 +49,10 @@ class stream<NextLayer>::read_some_op
stream<NextLayer>& ws_;
consuming_buffers<MutableBufferSequence> cb_;
std::size_t bytes_written_ = 0;
error_code ev_;
token tok_;
bool did_read_ = false;
bool dispatched_ = false;
bool did_read_ = false;
public:
read_some_op(read_some_op&&) = default;
@@ -553,11 +554,13 @@ operator()(
}
goto upcall;
}
close:
// Maybe send close frame, then teardown
BOOST_ASIO_CORO_YIELD
ws_.do_async_fail(code, ec, std::move(*this));
BOOST_ASSERT(! ws_.wr_block_);
//BOOST_ASSERT(! ws_.wr_block_);
goto upcall;
upcall:
BOOST_ASSERT(ws_.rd_block_ == tok_);