diff options
author | snowdrop | 2004-05-18 16:37:21 +0000 |
---|---|---|
committer | snowdrop | 2004-05-18 16:37:21 +0000 |
commit | f7bc3f4ac5affd8587d37f71bd2a23ea085b03b4 (patch) | |
tree | 64257705ed1605e484e954a8e7c52738d15454a7 | |
parent | 850754432a8a0e924cefd1c162b515a3ff9c7c9e (diff) | |
download | csoap-f7bc3f4ac5affd8587d37f71bd2a23ea085b03b4.tar.gz csoap-f7bc3f4ac5affd8587d37f71bd2a23ea085b03b4.tar.bz2 |
Added command line argument support for "-NHTTPtsig <signal>" by adding
_http_terminate_signal variable.
This defines the termination signal handler value.
Example :
./myserver -NHTTPtsig 2
will shutdown nano http properly by pressing ctrl-c (SIGINT = 2).
-rw-r--r-- | nanohttp/nanohttp-server.c | 12 | ||||
-rw-r--r-- | nanohttp/nanohttp-server.h | 3 |
2 files changed, 9 insertions, 6 deletions
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c index 23c71d9..a752fda 100644 --- a/nanohttp/nanohttp-server.c +++ b/nanohttp/nanohttp-server.c @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-server.c,v 1.6 2004/05/14 09:31:48 snowdrop Exp $ + * $Id: nanohttp-server.c,v 1.7 2004/05/18 16:37:21 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -58,7 +58,7 @@ static hsocket_t _httpd_socket; static hservice_t *_httpd_services_head = NULL; static hservice_t *_httpd_services_tail = NULL; static int _httpd_run = 1; - +static int _httpd_terminate_signal = SIGTERM; /* ----------------------------------------------------- FUNCTION: httpd_init @@ -76,6 +76,8 @@ int httpd_init(int argc, char *argv[]) for (i=0;i<argc;i++) { if (!strcmp(argv[i], NHTTPD_ARG_PORT) && i < argc-1) { _httpd_port = atoi(argv[i+1]); + } else if (!strcmp(argv[i], NHTTPD_ARG_TERMSIG) && i < argc-1) { + _httpd_terminate_signal = atoi(argv[i+1]); } } @@ -328,7 +330,7 @@ static void* httpd_session_main(void *data) ----------------------------------------------------- */ void httpd_term(int sig) { - if (sig == SIGTERM) + if (sig == _httpd_terminate_signal) _httpd_run = 0; } @@ -363,8 +365,8 @@ int httpd_run() return err; } - log_verbose1("registering sigterm handler"); - signal(SIGTERM,httpd_term); + log_verbose2("registering termination signal handler (SIGNAL:%d)", _httpd_terminate_signal); + signal(_httpd_terminate_signal, httpd_term); log_verbose2("listening to port '%d'", _httpd_port); diff --git a/nanohttp/nanohttp-server.h b/nanohttp/nanohttp-server.h index f1f2435..30992ac 100644 --- a/nanohttp/nanohttp-server.h +++ b/nanohttp/nanohttp-server.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: nanohttp-server.h,v 1.2 2004/01/30 16:37:50 snowdrop Exp $ + * $Id: nanohttp-server.h,v 1.3 2004/05/18 16:37:21 snowdrop Exp $ * * CSOAP Project: A http client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -30,6 +30,7 @@ #define NHTTPD_ARG_PORT "-NHTTPport" +#define NHTTPD_ARG_TERMSIG "-NHTTPtsig" typedef struct httpd_conn { |