From e5e25f5c17694831a36e30b0ed9773fc226b05c7 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 3 Aug 2017 04:21:24 -0700 Subject: [PATCH] Use correct handler signature in fail_op fix #716 --- CHANGELOG.md | 1 + include/boost/beast/websocket/impl/fail.ipp | 4 +-- test/beast/websocket/stream.cpp | 34 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffac253d..35409858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 99: * Log the value of LIB_DIR for doc builds (debug) +* Use correct handler signature in fail_op -------------------------------------------------------------------------------- diff --git a/include/boost/beast/websocket/impl/fail.ipp b/include/boost/beast/websocket/impl/fail.ipp index 69f8de0f..37c5e696 100644 --- a/include/boost/beast/websocket/impl/fail.ipp +++ b/include/boost/beast/websocket/impl/fail.ipp @@ -225,9 +225,9 @@ operator()(error_code ec, std::size_t) ws_.wr_op_.maybe_invoke(); if(! dispatched_) ws_.stream_.get_io_service().post( - bind_handler(std::move(h_), ec)); + bind_handler(std::move(h_), ec, 0)); else - h_(ec); + h_(ec, 0); } } // websocket diff --git a/test/beast/websocket/stream.cpp b/test/beast/websocket/stream.cpp index e114642e..b0a5880a 100644 --- a/test/beast/websocket/stream.cpp +++ b/test/beast/websocket/stream.cpp @@ -277,6 +277,15 @@ public: return ws.read(buffer); } + template< + class NextLayer, class MutableBufferSequence> + std::size_t + read_some(stream& ws, + MutableBufferSequence const& buffers) const + { + return ws.read_some(buffers); + } + template< class NextLayer, class ConstBufferSequence> void @@ -518,6 +527,20 @@ public: return bytes_written; } + template< + class NextLayer, class MutableBufferSequence> + std::size_t + read_some(stream& ws, + MutableBufferSequence const& buffers) const + { + error_code ec; + auto const bytes_written = + ws.async_read_some(buffers, yield_[ec]); + if(ec) + throw system_error{ec}; + return bytes_written; + } + template< class NextLayer, class ConstBufferSequence> void @@ -1674,6 +1697,17 @@ public: bool once; + // read_some + { + c.write(ws, sbuf("Hello")); + char buf[10]; + auto const bytes_written = + c.read_some(ws, buffer(buf, sizeof(buf))); + BEAST_EXPECT(bytes_written == 5); + buf[5] = 0; + BEAST_EXPECT(string_view(buf) == "Hello"); + } + // send ping and message { once = false;