Loading src/event/iocp.cpp +28 −1 Original line number Diff line number Diff line Loading @@ -209,6 +209,28 @@ namespace netplus { EventState* st = ST(ev); while (event::Running) { // Use select() with timeout before blocking accept() so we can // periodically check event::Running and exit cleanly when the // service is stopped. Calling closesocket() from another thread // to interrupt a blocking accept() is undefined behavior on Windows. { SOCKET sfd = (SOCKET)serverSock->fd(); fd_set rset; FD_ZERO(&rset); FD_SET(sfd, &rset); timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; int r = ::select(0, &rset, nullptr, nullptr, &tv); if (r == 0) continue; // timeout — re-check Running if (r == SOCKET_ERROR) { if (!event::Running) break; std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; } } if (!event::Running) break; std::unique_ptr<socket> csock; // Pre-allocate the child socket based on server socket type Loading Loading @@ -652,11 +674,16 @@ namespace netplus { }); } // Block like epoll loop (join workers) // Block like epoll loop (join workers, then accept threads) for (auto& t : st->workers) { if (t.joinable()) t.join(); } st->workers.clear(); for (auto& t : st->acceptThreads) { if (t.joinable()) t.join(); } st->acceptThreads.clear(); } // ================================================================ Loading Loading
src/event/iocp.cpp +28 −1 Original line number Diff line number Diff line Loading @@ -209,6 +209,28 @@ namespace netplus { EventState* st = ST(ev); while (event::Running) { // Use select() with timeout before blocking accept() so we can // periodically check event::Running and exit cleanly when the // service is stopped. Calling closesocket() from another thread // to interrupt a blocking accept() is undefined behavior on Windows. { SOCKET sfd = (SOCKET)serverSock->fd(); fd_set rset; FD_ZERO(&rset); FD_SET(sfd, &rset); timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; int r = ::select(0, &rset, nullptr, nullptr, &tv); if (r == 0) continue; // timeout — re-check Running if (r == SOCKET_ERROR) { if (!event::Running) break; std::this_thread::sleep_for(std::chrono::milliseconds(10)); continue; } } if (!event::Running) break; std::unique_ptr<socket> csock; // Pre-allocate the child socket based on server socket type Loading Loading @@ -652,11 +674,16 @@ namespace netplus { }); } // Block like epoll loop (join workers) // Block like epoll loop (join workers, then accept threads) for (auto& t : st->workers) { if (t.joinable()) t.join(); } st->workers.clear(); for (auto& t : st->acceptThreads) { if (t.joinable()) t.join(); } st->acceptThreads.clear(); } // ================================================================ Loading