X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fstatserv.c;h=487153e5649f8077f9d8a6cc607132bc04a40293;hp=8598891744ceb5ccf18721218e68508842f8b7e4;hb=b756b711841bac38e5b69baa51939ca9e1c01adb;hpb=08a57d6b7c0d759bf293fbad03d03363f1cb7bc5 diff --git a/src/statserv.c b/src/statserv.c index 8598891..487153e 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -1,5 +1,5 @@ /* This file is part of the YAZ toolkit. - * Copyright (C) 1995-2010 Index Data + * Copyright (C) 1995-2011 Index Data * See the file LICENSE for details. */ @@ -8,10 +8,13 @@ * \brief Implements GFS logic */ +#if HAVE_CONFIG_H +#include +#endif + #include #include #include -#include #ifdef WIN32 #include @@ -42,8 +45,6 @@ #if YAZ_POSIX_THREADS #include -#elif YAZ_GNU_THREADS -#include #endif #include @@ -62,6 +63,7 @@ #include "session.h" #include #include +#include static IOCHAN pListener = NULL; @@ -119,7 +121,8 @@ statserv_options_block control_block = { "", /* PID fname */ 0, /* background daemon */ "", /* SSL certificate filename */ - "" /* XML config filename */ + "", /* XML config filename */ + 1 /* keepalive */ }; static int max_sessions = 0; @@ -192,7 +195,7 @@ static char *nmem_dup_xml_content(NMEM n, xmlNodePtr ptr) cp = p->content; if (first) { - while(*cp && isspace(*cp)) + while(*cp && yaz_isspace(*cp)) cp++; if (*cp) first = 0; /* reset if we got non-whitespace out */ @@ -202,7 +205,7 @@ static char *nmem_dup_xml_content(NMEM n, xmlNodePtr ptr) } /* remove trailing whitespace */ cp = strlen((const char *)str) + str; - while (cp != str && isspace(cp[-1])) + while (cp != str && yaz_isspace(cp[-1])) cp--; *cp = '\0'; /* return resulting string */ @@ -607,6 +610,8 @@ static void xml_config_bend_stop(void) } } +static void remove_listeners(void); + /* * handle incoming connect requests. * The dynamic mode is a bit tricky mostly because we want to avoid @@ -906,6 +911,9 @@ static void listener(IOCHAN h, int event) return; } + if (control_block.one_shot) + remove_listeners(); + yaz_log(log_sessiondetail, "Connect from %s", cs_addrstr(new_line)); no_sessions++; @@ -947,18 +955,6 @@ static void listener(IOCHAN h, int event) pthread_t child_thread; pthread_create(&child_thread, 0, new_session, new_line); pthread_detach(child_thread); -#elif YAZ_GNU_THREADS - pth_attr_t attr; - pth_t child_thread; - - attr = pth_attr_new(); - pth_attr_set(attr, PTH_ATTR_JOINABLE, FALSE); - pth_attr_set(attr, PTH_ATTR_STACK_SIZE, 32*1024); - pth_attr_set(attr, PTH_ATTR_NAME, "session"); - yaz_log(YLOG_DEBUG, "pth_spawn begin"); - child_thread = pth_spawn(attr, new_session, new_line); - yaz_log(YLOG_DEBUG, "pth_spawn finish"); - pth_attr_destroy(attr); #else new_session(new_line); #endif @@ -1138,6 +1134,13 @@ static int add_listener(char *where, int listen_id) return 0; /* OK */ } +static void remove_listeners(void) +{ + IOCHAN l = pListener; + for (; l; l = l->next) + iochan_destroy(l); +} + #ifndef WIN32 /* UNIX only (for windows we don't need to catch the signals) */ static void catchchld(int num) @@ -1273,7 +1276,7 @@ int check_options(int argc, char **argv) get_logbits(1); - while ((ret = options("1a:iszSTl:v:u:c:w:t:k:d:A:p:DC:f:m:r:", + while ((ret = options("1a:iszSTl:v:u:c:w:t:k:Kd:A:p:DC:f:m:r:", argv, argc, &arg)) != -2) { switch (ret) @@ -1300,9 +1303,6 @@ int check_options(int argc, char **argv) #if YAZ_POSIX_THREADS control_block.dynamic = 0; control_block.threads = 1; -#elif YAZ_GNU_THREADS - control_block.dynamic = 0; - control_block.threads = 1; #else fprintf(stderr, "%s: Threaded mode not available.\n", me); return 1; @@ -1354,6 +1354,9 @@ int check_options(int argc, char **argv) } control_block.maxrecordsize = r * 1024; break; + case 'K': + control_block.keepalive = 0; + break; case 'i': control_block.inetd = 1; break;