@@ -121,7 +121,7 @@ class coro_http_server {
121
121
122
122
// close current connections.
123
123
{
124
- std::scoped_lock lock (conn_mtx_);
124
+ std::scoped_lock lock (* conn_mtx_);
125
125
for (auto &conn : connections_) {
126
126
conn.second ->close (false );
127
127
}
@@ -595,7 +595,7 @@ class coro_http_server {
595
595
}
596
596
597
597
size_t connection_count () {
598
- std::scoped_lock lock (conn_mtx_);
598
+ std::scoped_lock lock (* conn_mtx_);
599
599
return connections_.size ();
600
600
}
601
601
@@ -708,17 +708,20 @@ class coro_http_server {
708
708
conn->init_ssl (cert_file_, key_file_, passwd_);
709
709
}
710
710
#endif
711
-
711
+ std::weak_ptr<std::mutex> weak (conn_mtx_);
712
712
conn->set_quit_callback (
713
- [this ](const uint64_t &id) {
714
- std::scoped_lock lock (conn_mtx_);
715
- if (!connections_.empty ())
716
- connections_.erase (id);
713
+ [this , weak](const uint64_t &id) {
714
+ auto mtx = weak.lock ();
715
+ if (mtx) {
716
+ std::scoped_lock lock (*mtx);
717
+ if (!connections_.empty ())
718
+ connections_.erase (id);
719
+ }
717
720
},
718
721
conn_id);
719
722
720
723
{
721
- std::scoped_lock lock (conn_mtx_);
724
+ std::scoped_lock lock (* conn_mtx_);
722
725
connections_.emplace (conn_id, conn);
723
726
}
724
727
@@ -758,7 +761,7 @@ class coro_http_server {
758
761
std::unordered_map<uint64_t , std::shared_ptr<coro_http_connection>> conns;
759
762
760
763
{
761
- std::scoped_lock lock (conn_mtx_);
764
+ std::scoped_lock lock (* conn_mtx_);
762
765
for (auto it = connections_.begin ();
763
766
it != connections_.end ();) // no "++"!
764
767
{
@@ -966,7 +969,7 @@ class coro_http_server {
966
969
uint64_t conn_id_ = 0 ;
967
970
std::unordered_map<uint64_t , std::shared_ptr<coro_http_connection>>
968
971
connections_;
969
- std::mutex conn_mtx_;
972
+ std::shared_ptr<std:: mutex> conn_mtx_ = std::make_shared<std::mutex>() ;
970
973
std::chrono::steady_clock::duration check_duration_ =
971
974
std::chrono::seconds (15 );
972
975
std::chrono::steady_clock::duration timeout_duration_{};
0 commit comments