From: Adam Dickmeiss Date: Fri, 12 Feb 2010 10:49:56 +0000 (+0100) Subject: iochan_man_t in logic.c gone X-Git-Tag: v1.4.0~139 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=d24d65a3a42bbb6e8c8d0f919bf33510dd356a45;p=pazpar2-moved-to-github.git iochan_man_t in logic.c gone Unfortunately we've found another static list: connection_freelist in connection.c :-) --- diff --git a/src/client.h b/src/client.h index ff2e34b..31a4840 100644 --- a/src/client.h +++ b/src/client.h @@ -72,7 +72,8 @@ void client_destroy(struct client *c); void client_set_connection(struct client *cl, struct connection *con); void client_disconnect(struct client *cl); int client_prep_connection(struct client *cl, - int operation_timeout, int session_timeout); + int operation_timeout, int session_timeout, + iochan_man_t iochan); void client_start_search(struct client *cl); void client_set_session(struct client *cl, struct session *se); int client_is_active(struct client *cl); diff --git a/src/connection.c b/src/connection.c index f318378..dd61f1c 100644 --- a/src/connection.c +++ b/src/connection.c @@ -68,9 +68,9 @@ struct connection { struct connection *next; // next for same host or next in free list }; -static struct connection *connection_freelist = 0; +static struct connection *connection_freelist = 0; /* thread pr */ -static int connection_connect(struct connection *con); +static int connection_connect(struct connection *con, iochan_man_t iochan_man); static int connection_is_idle(struct connection *co) { @@ -135,7 +135,8 @@ void connection_destroy(struct connection *co) // client's database static struct connection *connection_create(struct client *cl, int operation_timeout, - int session_timeout) + int session_timeout, + iochan_man_t iochan_man) { struct connection *new; struct host *host = client_get_host(cl); @@ -159,7 +160,7 @@ static struct connection *connection_create(struct client *cl, new->operation_timeout = operation_timeout; new->session_timeout = session_timeout; if (host->ipport) - connection_connect(new); + connection_connect(new, iochan_man); return new; } @@ -278,7 +279,7 @@ void connection_release(struct connection *co) co->client = 0; } -void connect_resolver_host(struct host *host) +void connect_resolver_host(struct host *host, iochan_man_t iochan_man) { struct connection *con = host->connections; while (con) @@ -301,7 +302,7 @@ void connect_resolver_host(struct host *host) } else { - connection_connect(con); + connection_connect(con, iochan_man); client_start_search(con->client); } } @@ -340,7 +341,7 @@ static int maskfun(IOCHAN c) return ZOOM_connection_get_mask(co->link); } -static int connection_connect(struct connection *con) +static int connection_connect(struct connection *con, iochan_man_t iochan_man) { ZOOM_connection link = 0; struct host *host = connection_get_host(con); @@ -404,7 +405,7 @@ static int connection_connect(struct connection *con) iochan_setdata(con->iochan, con); iochan_setsocketfun(con->iochan, socketfun); iochan_setmaskfun(con->iochan, maskfun); - pazpar2_add_channel(con->iochan); + iochan_add(iochan_man, con->iochan); /* this fragment is bad DRY: from client_prep_connection */ client_set_state(con->client, Client_Connecting); @@ -419,7 +420,8 @@ const char *connection_get_url(struct connection *co) // Ensure that client has a connection associated int client_prep_connection(struct client *cl, - int operation_timeout, int session_timeout) + int operation_timeout, int session_timeout, + iochan_man_t iochan_man) { struct connection *co; struct session *se = client_get_session(cl); @@ -466,7 +468,8 @@ int client_prep_connection(struct client *cl, } else { - co = connection_create(cl, operation_timeout, session_timeout); + co = connection_create(cl, operation_timeout, session_timeout, + iochan_man); } } diff --git a/src/connection.h b/src/connection.h index 23bf4d7..94ad85e 100644 --- a/src/connection.h +++ b/src/connection.h @@ -34,7 +34,7 @@ struct host; struct session; void connection_destroy(struct connection *co); -void connect_resolver_host(struct host *host); +void connect_resolver_host(struct host *host, iochan_man_t iochan); const char *connection_get_url(struct connection *co); void connection_release(struct connection *co); ZOOM_connection connection_get_link(struct connection *co); diff --git a/src/database.c b/src/database.c index c2fb3b1..58cbd7e 100644 --- a/src/database.c +++ b/src/database.c @@ -87,7 +87,7 @@ static xmlDoc *get_explain_xml(struct conf_targetprofiles *targetprofiles, } // Create a new host structure for hostport -static struct host *create_host(const char *hostport) +static struct host *create_host(const char *hostport, iochan_man_t iochan_man) { struct host *host; @@ -96,7 +96,7 @@ static struct host *create_host(const char *hostport) host->connections = 0; host->ipport = 0; - if (host_getaddrinfo(host)) + if (host_getaddrinfo(host, iochan_man)) { xfree(host->hostport); xfree(host); @@ -107,16 +107,16 @@ static struct host *create_host(const char *hostport) return host; } -static struct host *find_host(const char *hostport) +static struct host *find_host(const char *hostport, iochan_man_t iochan_man) { struct host *p; for (p = hosts; p; p = p->next) if (!strcmp(p->hostport, hostport)) return p; - return create_host(hostport); + return create_host(hostport, iochan_man); } -int resolve_database(struct database *db) +int resolve_database(struct conf_service *service, struct database *db) { if (db->host == 0) { @@ -126,7 +126,7 @@ int resolve_database(struct database *db) strcpy(hostport, db->url); if ((p = strchr(hostport, '/'))) *p = '\0'; - if (!(host = find_host(hostport))) + if (!(host = find_host(hostport, service->server->iochan_man))) return -1; db->host = host; } @@ -137,7 +137,7 @@ void resolve_databases(struct conf_service *service) { struct database *db = service->databases; for (; db; db = db->next) - resolve_database(db); + resolve_database(service, db); } struct database *new_database(const char *id, NMEM nmem) diff --git a/src/database.h b/src/database.h index cf12e9d..1c0d861 100644 --- a/src/database.h +++ b/src/database.h @@ -26,6 +26,6 @@ int session_grep_databases(struct session *se, const char *filter, int predef_grep_databases(void *context, struct conf_service *service, void (*fun)(void *context, struct database *db)); int match_zurl(const char *zurl, const char *pattern); -int resolve_database(struct database *db); +int resolve_database(struct conf_service *service, struct database *db); struct database *new_database(const char *id, NMEM nmem); #endif diff --git a/src/getaddrinfo.c b/src/getaddrinfo.c index f1525ea..865d20a 100644 --- a/src/getaddrinfo.c +++ b/src/getaddrinfo.c @@ -64,6 +64,7 @@ struct work { char *hostport; /* hostport to be resolved in separate thread */ char *ipport; /* result or NULL if it could not be resolved */ struct host *host; /* host that we're dealing with - mother thread */ + iochan_man_t iochan_man; /* iochan manager */ }; static int log_level = YLOG_LOG; @@ -158,14 +159,14 @@ void iochan_handler(struct iochan *i, int event) { struct work *w = sel_thread_result(p); w->host->ipport = w->ipport; - connect_resolver_host(w->host); + connect_resolver_host(w->host, w->iochan_man); xfree(w); } } static sel_thread_t resolver_thread = 0; -static void getaddrinfo_start(void) +static void getaddrinfo_start(iochan_man_t iochan_man) { int fd; sel_thread_t p = resolver_thread = @@ -180,14 +181,14 @@ static void getaddrinfo_start(void) { IOCHAN chan = iochan_create(fd, iochan_handler, EVENT_INPUT); iochan_setdata(chan, p); - pazpar2_add_channel(chan); + iochan_add(iochan_man, chan); } yaz_log(log_level, "resolver start"); resolver_thread = p; } #endif -int host_getaddrinfo(struct host *host) +int host_getaddrinfo(struct host *host, iochan_man_t iochan_man) { struct work *w = xmalloc(sizeof(*w)); int use_thread = 1; /* =0 to disable threading entirely */ @@ -195,11 +196,12 @@ int host_getaddrinfo(struct host *host) w->hostport = host->hostport; w->ipport = 0; w->host = host; + w->iochan_man = iochan_man; #if USE_THREADED_RESOLVER if (use_thread) { if (resolver_thread == 0) - getaddrinfo_start(); + getaddrinfo_start(iochan_man); assert(resolver_thread); sel_thread_add(resolver_thread, w); return 0; diff --git a/src/http.c b/src/http.c index 2685752..5158ddb 100644 --- a/src/http.c +++ b/src/http.c @@ -799,7 +799,8 @@ static int http_proxy(struct http_request *rq) // We will add EVENT_OUTPUT below p->iochan = iochan_create(sock, proxy_io, EVENT_INPUT); iochan_setdata(p->iochan, p); - pazpar2_add_channel(p->iochan); + + iochan_add(ser->iochan_man, p->iochan); } // Do _not_ modify Host: header, just checking it's existence @@ -1175,8 +1176,7 @@ static void http_accept(IOCHAN i, int event) server); ch->iochan = c; iochan_setdata(c, ch); - - pazpar2_add_channel(c); + iochan_add(server->iochan_man, c); } /* Create a http-channel listener, syntax [host:]port */ @@ -1247,7 +1247,8 @@ int http_init(const char *addr, struct conf_server *server) c = iochan_create(l, http_accept, EVENT_INPUT | EVENT_EXCEPT); iochan_setdata(c, server); - pazpar2_add_channel(c); + + iochan_add(server->iochan_man, c); return 0; } diff --git a/src/http_command.c b/src/http_command.c index 5fc7096..913af79 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -116,7 +116,7 @@ struct http_session *http_session_create(struct conf_service *service, iochan_setdata(r->timeout_iochan, r); iochan_settimeout(r->timeout_iochan, service->session_timeout); - pazpar2_add_channel(r->timeout_iochan); + iochan_add(service->server->iochan_man, r->timeout_iochan); return r; } diff --git a/src/logic.c b/src/logic.c index 28929de..f6f6cbd 100644 --- a/src/logic.c +++ b/src/logic.c @@ -491,7 +491,8 @@ enum pazpar2_error_code search(struct session *se, { no_working++; if (client_prep_connection(cl, se->service->z3950_operation_timeout, - se->service->z3950_session_timeout)) + se->service->z3950_session_timeout, + se->service->server->iochan_man)) client_start_search(cl); } } @@ -552,7 +553,7 @@ static struct session_database *load_session_database(struct session *se, { struct database *db = new_database(id, se->session_nmem); - resolve_database(db); + resolve_database(se->service, db); session_init_databases_fun((void*) se, db); @@ -810,27 +811,6 @@ void statistics(struct session *se, struct statistics *stat) stat->num_clients = count; } - -// Master list of connections we're handling events to -static iochan_man_t pazpar2_chan_man = 0; /* thread pr */ - -void pazpar2_chan_man_start(int no_threads) -{ - pazpar2_chan_man = iochan_man_create(no_threads); -} - -void pazpar2_add_channel(IOCHAN chan) -{ - assert(pazpar2_chan_man); - iochan_add(pazpar2_chan_man, chan); -} - -void pazpar2_event_loop() -{ - assert(pazpar2_chan_man); - iochan_man_events(pazpar2_chan_man); -} - static struct record_metadata *record_metadata_init( NMEM nmem, const char *value, enum conf_metadata_type type, struct _xmlAttr *attr) diff --git a/src/pazpar2.c b/src/pazpar2.c index 88b549d..f94d585 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -40,9 +40,7 @@ void child_handler(void *data) { struct conf_config *config = (struct conf_config *) data; - config_start_databases(config); - - pazpar2_event_loop(); + config_process_events(config); config_destroy(config); } diff --git a/src/pazpar2.h b/src/pazpar2.h index 4a9c26a..7a55262 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -162,10 +162,7 @@ int session_active_clients(struct session *s); void session_apply_setting(struct session *se, char *dbname, char *setting, char *value); const char *session_setting_oneval(struct session_database *db, int offset); -void pazpar2_add_channel(IOCHAN c); -void pazpar2_event_loop(void); - -int host_getaddrinfo(struct host *host); +int host_getaddrinfo(struct host *host, iochan_man_t iochan_man); struct record *ingest_record(struct client *cl, const char *rec, int record_no); diff --git a/src/pazpar2_config.c b/src/pazpar2_config.c index 8943b20..4930f73 100644 --- a/src/pazpar2_config.c +++ b/src/pazpar2_config.c @@ -48,8 +48,10 @@ struct conf_config { NMEM nmem; /* for conf_config and servers memory */ struct conf_server *servers; + int no_threads; WRBUF confdir; + iochan_man_t iochan_man; }; @@ -719,6 +721,7 @@ static struct conf_server *server_create(struct conf_config *config, server->mergekey_pct = 0; server->server_settings = 0; server->http_server = 0; + server->iochan_man = 0; if (server_id) { @@ -956,6 +959,7 @@ struct conf_config *config_create(const char *fname, int verbose) config->nmem = nmem; config->servers = 0; config->no_threads = 0; + config->iochan_man = 0; config->confdir = wrbuf_alloc(); if ((p = strrchr(fname, @@ -1036,7 +1040,7 @@ void config_stop_listeners(struct conf_config *conf) http_close_server(ser); } -void config_start_databases(struct conf_config *conf) +void config_process_events(struct conf_config *conf) { struct conf_server *ser; for (ser = conf->servers; ser; ser = ser->next) @@ -1050,17 +1054,21 @@ void config_start_databases(struct conf_config *conf) } http_mutex_init(ser); } + iochan_man_events(conf->iochan_man); } int config_start_listeners(struct conf_config *conf, const char *listener_override) { struct conf_server *ser; - pazpar2_chan_man_start(conf->no_threads); + + conf->iochan_man = iochan_man_create(conf->no_threads); for (ser = conf->servers; ser; ser = ser->next) { WRBUF w = wrbuf_alloc(); int r; + + ser->iochan_man = conf->iochan_man; if (listener_override) { wrbuf_puts(w, listener_override); diff --git a/src/pazpar2_config.h b/src/pazpar2_config.h index 1ae1ee4..5b5eee6 100644 --- a/src/pazpar2_config.h +++ b/src/pazpar2_config.h @@ -145,6 +145,7 @@ struct conf_server struct conf_server *next; struct conf_config *config; http_server_t http_server; + iochan_man_t iochan_man; }; struct conf_targetprofiles @@ -157,7 +158,7 @@ struct conf_targetprofiles struct conf_config *config_create(const char *fname, int verbose); void config_destroy(struct conf_config *config); -void config_start_databases(struct conf_config *config); +void config_process_events(struct conf_config *config); struct conf_service *locate_service(struct conf_server *server, const char *service_id); diff --git a/src/settings.h b/src/settings.h index 15fbf3c..43d162e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -68,8 +68,6 @@ void settings_read_node_x(xmlNode *n, void expand_settings_array(struct setting ***set_ar, int *num, int offset, NMEM nmem); -void pazpar2_chan_man_start(int no_threads); - #endif /*