fix bad_weak_ptr

pass weak_ptr of connection to http2_handler, avoid calling `do_write` after connection is destroyed.
This commit is contained in:
noosc 2019-05-24 16:24:41 +08:00 committed by GitHub
parent f82fb52187
commit 48e2faa22e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -87,10 +87,15 @@ public:
/// Start the first asynchronous operation for the connection.
void start() {
boost::system::error_code ec;
std::weak_ptr<connection> weak_self = this->shared_from_this();
handler_ = std::make_shared<http2_handler>(
GET_IO_SERVICE(socket_), socket_.lowest_layer().remote_endpoint(ec),
[this]() { do_write(); }, mux_);
[weak_self]() {
auto shared_connection = weak_self.lock();
if (!shared_connection) { return; }
shared_connection->do_write();
}, mux_);
if (handler_->start() != 0) {
stop();
return;