File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -5507,6 +5507,8 @@ inline bool Server::listen_internal() {
5507
5507
// Try to accept new connections after a short sleep.
5508
5508
std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
5509
5509
continue ;
5510
+ } else if (errno == EINTR || errno == EAGAIN) {
5511
+ continue ;
5510
5512
}
5511
5513
if (svr_sock_ != INVALID_SOCKET) {
5512
5514
detail::close_socket (svr_sock_);
Original file line number Diff line number Diff line change 1
1
#include < httplib.h>
2
+ #include < signal.h>
2
3
3
4
#include < gtest/gtest.h>
4
5
@@ -943,6 +944,44 @@ TEST(UrlWithSpace, Redirect_Online) {
943
944
944
945
#endif
945
946
947
+ #if !defined(_WIN32) && !defined(_WIN64)
948
+ TEST (ReceiveSignals, Signal) {
949
+ auto setupSignalHandlers = []() {
950
+ struct sigaction act;
951
+
952
+ sigemptyset (&act.sa_mask );
953
+ act.sa_flags = SA_SIGINFO;
954
+ act.sa_sigaction = [](int sig, siginfo_t *, void *) {
955
+ switch (sig) {
956
+ case SIGINT:
957
+ default : break ;
958
+ }
959
+ };
960
+ ::sigaction (SIGINT, &act, nullptr );
961
+ };
962
+
963
+ Server svr;
964
+ int port = 0 ;
965
+ auto thread = std::thread ([&]() {
966
+ setupSignalHandlers ();
967
+ port = svr.bind_to_any_port (" localhost" );
968
+ svr.listen_after_bind ();
969
+ });
970
+
971
+ while (!svr.is_running ()) {
972
+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
973
+ }
974
+
975
+ ASSERT_TRUE (svr.is_running ());
976
+ pthread_kill (thread.native_handle (), SIGINT);
977
+ std::this_thread::sleep_for (std::chrono::milliseconds (100 ));
978
+ ASSERT_TRUE (svr.is_running ());
979
+ svr.stop ();
980
+ thread.join ();
981
+ ASSERT_FALSE (svr.is_running ());
982
+ }
983
+ #endif
984
+
946
985
TEST (RedirectToDifferentPort, Redirect) {
947
986
Server svr1;
948
987
svr1.Get (" /1" , [&](const Request & /* req*/ , Response &res) {
You can’t perform that action at this time.
0 commit comments