From af2e686d7372a0a2f4175cbe46d99fadd64bb465 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sat, 5 Mar 2005 12:14:12 +0000 Subject: [PATCH] WIN32 Updates for GFS to use TLS for control block. --- src/seshigh.c | 16 +++++++++------- src/statserv.c | 51 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/seshigh.c b/src/seshigh.c index 1aea670..65c2626 100644 --- a/src/seshigh.c +++ b/src/seshigh.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.50 2005-03-05 09:17:27 adam Exp $ + * $Id: seshigh.c,v 1.51 2005-03-05 12:14:12 adam Exp $ */ /** * \file seshigh.c @@ -927,15 +927,16 @@ static char *srw_bend_explain_default(void *handle, bend_explain_rr *rr) if (!strcmp((const char *) ptr->name, "explain")) { int len; - ptr = xmlCopyNode(ptr, 1); + xmlDocPtr doc = xmlNewDoc("1.0"); + xmlChar *buf_out; + char *content; - xmlDocPtr doc = xmlNewDoc((const xmlChar *) "1.0"); + ptr = xmlCopyNode(ptr, 1); xmlDocSetRootElement(doc, ptr); - xmlChar *buf_out; xmlDocDumpMemory(doc, &buf_out, &len); - char *content = (char*) odr_malloc(rr->stream, 1+len); + content = (char*) odr_malloc(rr->stream, 1+len); memcpy(content, buf_out, len); content[len] = '\0'; @@ -1063,10 +1064,11 @@ static void srw_bend_scan(association *assoc, request *req, { if (assoc->cql_transform) { + int srw_error; bsrr->scanClause = 0; bsrr->attributeset = VAL_NONE; bsrr->term = odr_malloc(assoc->decode, sizeof(*bsrr->term)); - int srw_error = cql2pqf_scan(assoc->encode, + srw_error = cql2pqf_scan(assoc->encode, srw_req->scanClause.cql, assoc->cql_transform, bsrr->term); @@ -1758,7 +1760,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb) assoc->init->implementation_name, odr_prepend(assoc->encode, "GFS", resp->implementationName)); - version = odr_strdup(assoc->encode, "$Revision: 1.50 $"); + version = odr_strdup(assoc->encode, "$Revision: 1.51 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; resp->implementationVersion = odr_prepend(assoc->encode, diff --git a/src/statserv.c b/src/statserv.c index 67152e6..19db7f4 100644 --- a/src/statserv.c +++ b/src/statserv.c @@ -5,7 +5,7 @@ * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.24 2005-03-03 23:16:20 adam Exp $ + * $Id: statserv.c,v 1.25 2005-03-05 12:14:12 adam Exp $ */ /** @@ -69,7 +69,10 @@ static NMEM gfs_nmem = 0; static char *me = "statserver"; /* log prefix */ static char *programname="statserver"; /* full program name */ -#if YAZ_POSIX_THREADS +#ifdef WIN32 +DWORD current_control_tls; +static int init_control_tls = 0; +#elif YAZ_POSIX_THREADS static pthread_key_t current_control_tls; static int init_control_tls = 0; #else @@ -269,6 +272,7 @@ int control_association(association *assoc, const char *host, int force_open) assoc->server_node_ptr = gfs->server_node_ptr; assoc->last_control = &gfs->cb; statserv_setcontrol(&gfs->cb); + yaz_log(YLOG_DEBUG, "server select: %s", gfs->cb.configname); return 1; } } @@ -276,6 +280,7 @@ int control_association(association *assoc, const char *host, int force_open) assoc->last_control = 0; assoc->cql_transform = 0; assoc->server_node_ptr = 0; + yaz_log(YLOG_DEBUG, "server select: no match"); return 0; } else @@ -284,6 +289,7 @@ int control_association(association *assoc, const char *host, int force_open) assoc->last_control = &control_block; assoc->cql_transform = 0; assoc->server_node_ptr = 0; + yaz_log(YLOG_DEBUG, "server select: config=%s", control_block.configname); return 1; } } @@ -299,9 +305,10 @@ static void xml_config_read() return; for (ptr = ptr->children; ptr; ptr = ptr->next) { + struct _xmlAttr *attr; if (ptr->type != XML_ELEMENT_NODE) continue; - struct _xmlAttr *attr = ptr->properties; + attr = ptr->properties; if (!strcmp((const char *) ptr->name, "listen")) { /* @@ -377,6 +384,14 @@ static void xml_config_read() static void xml_config_open() { +#ifdef WIN32 + init_control_tls = 1; + current_control_tls = TlsAlloc(); +#elif YAZ_POSIX_THREADS + init_control_tls = 1; + pthread_key_create(¤t_control_tls, 0); +#endif + gfs_nmem = nmem_create(); #if HAVE_XML2 if (control_block.xml_config[0] == '\0') @@ -392,7 +407,6 @@ static void xml_config_open() } } xml_config_read(); - #endif } @@ -407,6 +421,13 @@ static void xml_config_close() #endif gfs_server_list = 0; nmem_destroy(gfs_nmem); +#ifdef WIN32 + if (init_control_tls) + TlsFree(current_control_tls); +#elif YAZ_POSIX_THREADS + if (init_control_tls) + pthread_key_delete(current_control_tls); +#endif } static void xml_config_add_listeners() @@ -674,7 +695,7 @@ static void listener(IOCHAN h, int event) yaz_log(YLOG_DEBUG, "Accept ok"); if (!(new_chan = iochan_create(cs_fileno(new_line), ir_session, - EVENT_INPUT, parent_chan->port))) + EVENT_INPUT, parent_chan->chan_id))) { yaz_log(YLOG_FATAL, "Failed to create iochan"); iochan_destroy(h); @@ -751,9 +772,6 @@ void statserv_closedown() iochan_destroy(p); } xml_config_close(); -#if YAZ_POSIX_THREADS - pthread_key_delete(current_control_tls); -#endif } void sigterm(int sig) @@ -1031,7 +1049,12 @@ static void catchchld(int num) statserv_options_block *statserv_getcontrol(void) { -#if YAZ_POSIX_THREADS +#ifdef WIN32 + if (init_control_tls) + return (statserv_options_block *) TlsGetValue(current_control_tls); + else + return &control_block; +#elif YAZ_POSIX_THREADS if (init_control_tls) return pthread_getspecific(current_control_tls); else @@ -1045,7 +1068,10 @@ statserv_options_block *statserv_getcontrol(void) void statserv_setcontrol(statserv_options_block *block) { -#if YAZ_POSIX_THREADS +#ifdef WIN32 + if (init_control_tls) + TlsSetValue(current_control_tls, block); +#elif YAZ_POSIX_THREADS if (init_control_tls) pthread_setspecific(current_control_tls, block); #else @@ -1081,11 +1107,6 @@ int statserv_start(int argc, char **argv) if (control_block.options_func(argc, argv)) return 1; -#if YAZ_POSIX_THREADS - init_control_tls = 1; - pthread_key_create(¤t_control_tls, 0); -#endif - xml_config_open(); xml_config_bend_start(); -- 1.7.10.4