From 9fd28d5703ddb7d3a815b6366e92f017c38d0818 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Thu, 12 Jun 2025 22:09:06 -0500 Subject: [PATCH] fix epoll workers not closing --- epoll_socket.hpp | 9 ++++++--- main.cpp | 5 ++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/epoll_socket.hpp b/epoll_socket.hpp index 989499b..717f95e 100644 --- a/epoll_socket.hpp +++ b/epoll_socket.hpp @@ -34,8 +34,11 @@ public: std::array events; while (running_) { - int num_events = epoll_wait(epoll_fd_, events.data(), MAX_EVENTS, -1); - if (num_events == -1) break; + int num_events = epoll_wait(epoll_fd_, events.data(), MAX_EVENTS, 1000); + if (num_events == -1) { + if (errno == EINTR) continue; + break; + } for (int i = 0; i < num_events; ++i) { if (events[i].data.fd == server_fd_) { @@ -153,4 +156,4 @@ private: inline void handle_client_event(int client_fd) { if (on_data_) on_data_(client_fd); } -}; +}; \ No newline at end of file diff --git a/main.cpp b/main.cpp index 9496b57..7659fe1 100644 --- a/main.cpp +++ b/main.cpp @@ -7,8 +7,7 @@ HttpServer* server = nullptr; void signal_handler(int sig) { if (server) { std::cout << "\nShutting down server...\n"; - delete server; - exit(0); + server->stop(); } } @@ -87,4 +86,4 @@ int main() { delete server; return 0; -} +} \ No newline at end of file