fix epoll workers not closing
This commit is contained in:
parent
0f5ce5b524
commit
9fd28d5703
@ -34,8 +34,11 @@ public:
|
|||||||
std::array<epoll_event, MAX_EVENTS> events;
|
std::array<epoll_event, MAX_EVENTS> events;
|
||||||
|
|
||||||
while (running_) {
|
while (running_) {
|
||||||
int num_events = epoll_wait(epoll_fd_, events.data(), MAX_EVENTS, -1);
|
int num_events = epoll_wait(epoll_fd_, events.data(), MAX_EVENTS, 1000);
|
||||||
if (num_events == -1) break;
|
if (num_events == -1) {
|
||||||
|
if (errno == EINTR) continue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < num_events; ++i) {
|
for (int i = 0; i < num_events; ++i) {
|
||||||
if (events[i].data.fd == server_fd_) {
|
if (events[i].data.fd == server_fd_) {
|
||||||
@ -153,4 +156,4 @@ private:
|
|||||||
inline void handle_client_event(int client_fd) {
|
inline void handle_client_event(int client_fd) {
|
||||||
if (on_data_) on_data_(client_fd);
|
if (on_data_) on_data_(client_fd);
|
||||||
}
|
}
|
||||||
};
|
};
|
5
main.cpp
5
main.cpp
@ -7,8 +7,7 @@ HttpServer* server = nullptr;
|
|||||||
void signal_handler(int sig) {
|
void signal_handler(int sig) {
|
||||||
if (server) {
|
if (server) {
|
||||||
std::cout << "\nShutting down server...\n";
|
std::cout << "\nShutting down server...\n";
|
||||||
delete server;
|
server->stop();
|
||||||
exit(0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,4 +86,4 @@ int main() {
|
|||||||
|
|
||||||
delete server;
|
delete server;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user