Created
April 9, 2020 19:57
-
-
Save madmongo1/3ff873c6355282d3c9a5fe0dc81eebc0 to your computer and use it in GitHub Desktop.
Here's what I mean...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template< | |
class Stream, class DynamicBuffer, | |
class ParserType> | |
struct read_msg_op | |
: public asio::coroutine | |
, public enable_stable_storage | |
{ | |
using parser_type = ParserType; | |
using message_type = | |
typename parser_type::value_type; | |
struct data | |
{ | |
Stream& s; | |
message_type& m; | |
parser_type p; | |
data( | |
Stream& s_, | |
message_type& m_) | |
: s(s_) | |
, m(m_) | |
, p(std::move(m)) | |
{ | |
} | |
}; | |
data* d_; | |
Stream& s_; | |
DynamicBuffer& b_; | |
message_type& m_; | |
public: | |
read_msg_op( | |
Stream& s, | |
DynamicBuffer& b, | |
message_type& m) | |
: d_(nullptr) /*(beast::allocate_stable<data>( | |
*this, s, m)) */ | |
, s_(s) | |
, b_(b) | |
, m_(m) | |
{ | |
// http::async_read(d_.s, b, d_.p, std::move(*this)); | |
} | |
template<class Self> | |
void | |
operator()( | |
Self& self, | |
error_code ec = error_code(), | |
std::size_t bytes_transferred = 0) | |
{ | |
BOOST_ASIO_CORO_REENTER(this) | |
{ | |
try | |
{ | |
d_(this->allocate<data>(self, s_, m_)); | |
} | |
catch(std::exception&) | |
{ | |
ec = asio::error::no_memory; | |
} | |
if (ec) | |
{ | |
BOOST_ASIO_CORO_YIELD | |
asio::post(beast::bind_front_handler(std::move(self), ec)); | |
return complete(self, ec, bytes_transferred); | |
} | |
else | |
{ | |
BOOST_ASIO_CORO_YIELD | |
http::async_read(d_->s, b_, d_->p, std::move(self)); | |
if(! ec) | |
d_->m = d_->p.release(); | |
complete(self, ec, bytes_transferred); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment