diff --git a/net/http/server.cpp b/net/http/server.cpp index 27b7ecc6..a2818f0b 100644 --- a/net/http/server.cpp +++ b/net/http/server.cpp @@ -31,6 +31,7 @@ limitations under the License. #include "client.h" #include "message.h" #include "body.h" +#include #ifndef MSG_MORE @@ -65,8 +66,9 @@ class HTTPServerImpl : public HTTPServer { } status = Status::running; HandlerRecord m_default_handler = {"", nullptr, false, {this, &HTTPServerImpl::not_found_handler}}; - uint64_t m_workers = 0; + std::atomic m_workers{0}; intrusive_list m_connection_list; + photon::spinlock m_connection_list_lock; std::vector m_handlers; HTTPServerImpl() {} @@ -107,8 +109,14 @@ class HTTPServerImpl : public HTTPServer { m_workers++; DEFER(m_workers--); SockItem sock_item(sock); - m_connection_list.push_back(&sock_item); - DEFER(m_connection_list.erase(&sock_item)); + { + SCOPED_LOCK(m_connection_list_lock); + m_connection_list.push_back(&sock_item); + } + DEFER({ + SCOPED_LOCK(m_connection_list_lock); + m_connection_list.erase(&sock_item); + }); char req_buf[64*1024]; char resp_buf[64*1024];