@@ -716,38 +716,40 @@ namespace crow // NOTE: Already documented in "crow/app.h"
716716 // / Also destroys the object if the Close flag is set.
717717 void do_write ()
718718 {
719- if (write_buffers_.empty ()) return ;
719+ if (sending_buffers_.empty ()) {
720+ if (write_buffers_.empty ()) return ;
720721
721- sending_buffers_.swap (write_buffers_);
722- std::vector<asio::const_buffer> buffers;
723- buffers.reserve (sending_buffers_.size ());
724- for (auto & s : sending_buffers_)
725- {
726- buffers.emplace_back (asio::buffer (s));
727- }
728- auto watch = std::weak_ptr<void >{anchor_};
729- asio::async_write (
730- adaptor_.socket (), buffers,
731- [shared_this = this ->shared_from_this (), watch](const error_code& ec, std::size_t /* bytes_transferred*/ ) {
732- auto anchor = watch.lock ();
733- if (anchor == nullptr )
734- return ;
735-
736- if (!ec && !shared_this->close_connection_ )
737- {
738- shared_this->sending_buffers_ .clear ();
739- if (!shared_this->write_buffers_ .empty ())
740- shared_this->do_write ();
741- if (shared_this->has_sent_close_ )
722+ sending_buffers_.swap (write_buffers_);
723+ std::vector<asio::const_buffer> buffers;
724+ buffers.reserve (sending_buffers_.size ());
725+ for (auto &s: sending_buffers_)
726+ {
727+ buffers.emplace_back (asio::buffer (s));
728+ }
729+ auto watch = std::weak_ptr<void >{anchor_};
730+ asio::async_write (
731+ adaptor_.socket (), buffers,
732+ [shared_this = this ->shared_from_this (), watch](const error_code &ec, std::size_t /* bytes_transferred*/ ) {
733+ auto anchor = watch.lock ();
734+ if (anchor == nullptr )
735+ return ;
736+
737+ if (!ec && !shared_this->close_connection_ )
738+ {
739+ shared_this->sending_buffers_ .clear ();
740+ if (!shared_this->write_buffers_ .empty ())
741+ shared_this->do_write ();
742+ if (shared_this->has_sent_close_ )
743+ shared_this->close_connection_ = true ;
744+ }
745+ else
746+ {
747+ shared_this->sending_buffers_ .clear ();
742748 shared_this->close_connection_ = true ;
743- }
744- else
745- {
746- shared_this->sending_buffers_ .clear ();
747- shared_this->close_connection_ = true ;
748- shared_this->check_destroy ();
749- }
750- });
749+ shared_this->check_destroy ();
750+ }
751+ });
752+ }
751753 }
752754
753755 // / Destroy the Connection.
0 commit comments