@@ -64,6 +64,7 @@ char* myoptarg = NULL;
6464 #include <unistd.h>
6565 #include <fcntl.h>
6666 #include <errno.h>
67+ #include <signal.h>
6768 #define SOCKET_T int
6869#ifndef INVALID_SOCKET
6970 #define INVALID_SOCKET (-1)
@@ -82,6 +83,17 @@ char* myoptarg = NULL;
8283/* Simple logging macro */
8384#define LOG_ERROR (...) fprintf(stderr, __VA_ARGS__)
8485
86+ #ifndef _WIN32
87+ /* Signal handler flag */
88+ static volatile int got_signal = 0 ;
89+
90+ static void sig_handler (int sig )
91+ {
92+ (void )sig ;
93+ got_signal = 1 ;
94+ }
95+ #endif
96+
8597/* Index file entry structure */
8698typedef struct IndexEntry {
8799 char status ; /* V=valid, R=revoked, E=expired */
@@ -797,8 +809,21 @@ THREAD_RETURN WOLFSSL_THREAD ocsp_responder_test(void* args)
797809 }
798810 printf ("OCSP Responder listening on port %d\n" , opts .port );
799811
812+ #ifndef _WIN32
813+ /* Install signal handlers for clean shutdown */
814+ signal (SIGTERM , sig_handler );
815+ signal (SIGINT , sig_handler );
816+ if (opts .verbose ) {
817+ printf ("Signal handlers installed\n" );
818+ }
819+ #endif
820+
800821 /* Main loop */
801- while (opts .nrequests == 0 || requestsProcessed < opts .nrequests ) {
822+ while ((opts .nrequests == 0 || requestsProcessed < opts .nrequests )
823+ #ifndef _WIN32
824+ && !got_signal
825+ #endif
826+ ) {
802827 struct sockaddr_in clientAddr ;
803828 socklen_t clientAddrLen = sizeof (clientAddr );
804829 int recvLen ;
0 commit comments