@@ -257,7 +257,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
257257// / Sets a flag to destroy the object once the message is sent.
258258void close (std::stringconst & msg,uint16_t status_code)override
259259 {
260- dispatch ([this , msg, status_code]()mutable {
260+ dispatch ([this ,shared_this = this -> shared_from_this (), msg, status_code]()mutable {
261261 has_sent_close_ =true ;
262262if (has_recv_close_ && !is_close_handler_called_)
263263 {
@@ -371,7 +371,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
371371// asio::async_read(adaptor_.socket(), asio::buffer(&mini_header_, 1),
372372 adaptor_.socket ().async_read_some (
373373asio::buffer (&mini_header_,2 ),
374- [this ](const error_code& ec, std::size_t
374+ [this , shared_this = this -> shared_from_this () ](const error_code& ec, std::size_t
375375#ifdef CROW_ENABLE_DEBUG
376376 bytes_transferred
377377#endif
@@ -439,7 +439,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
439439 remaining_length16_ =0 ;
440440asio::async_read (
441441 adaptor_.socket (),asio::buffer (&remaining_length16_,2 ),
442- [this ](const error_code& ec, std::size_t
442+ [this , shared_this = this -> shared_from_this () ](const error_code& ec, std::size_t
443443#ifdef CROW_ENABLE_DEBUG
444444 bytes_transferred
445445#endif
@@ -475,7 +475,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
475475 {
476476asio::async_read (
477477 adaptor_.socket (),asio::buffer (&remaining_length_,8 ),
478- [this ](const error_code& ec, std::size_t
478+ [this , shared_this = this -> shared_from_this () ](const error_code& ec, std::size_t
479479#ifdef CROW_ENABLE_DEBUG
480480 bytes_transferred
481481#endif
@@ -519,7 +519,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
519519 {
520520asio::async_read (
521521 adaptor_.socket (),asio::buffer ((char *)&mask_,4 ),
522- [this ](const error_code& ec, std::size_t
522+ [this , shared_this = this -> shared_from_this () ](const error_code& ec, std::size_t
523523#ifdef CROW_ENABLE_DEBUG
524524 bytes_transferred
525525#endif
@@ -561,7 +561,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
561561 to_read = remaining_length_;
562562 adaptor_.socket ().async_read_some (
563563asio::buffer (buffer_,static_cast <std::size_t >(to_read)),
564- [this ](const error_code& ec, std::size_t bytes_transferred) {
564+ [this , shared_this = this -> shared_from_this () ](const error_code& ec, std::size_t bytes_transferred) {
565565 is_reading =false ;
566566
567567if (!ec)
@@ -728,7 +728,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
728728auto watch = std::weak_ptr<void >{anchor_};
729729asio::async_write (
730730 adaptor_.socket (), buffers,
731- [this , watch](const error_code& ec, std::size_t /* bytes_transferred*/ ) {
731+ [this ,shared_this = this -> shared_from_this (), watch](const error_code& ec, std::size_t /* bytes_transferred*/ ) {
732732auto anchor = watch.lock ();
733733if (anchor ==nullptr )
734734return ;