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);
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)
{
// 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);
new->operation_timeout = operation_timeout;
new->session_timeout = session_timeout;
if (host->ipport)
- connection_connect(new);
+ connection_connect(new, iochan_man);
return new;
}
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)
}
else
{
- connection_connect(con);
+ connection_connect(con, iochan_man);
client_start_search(con->client);
}
}
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);
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);
// 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);
}
else
{
- co = connection_create(cl, operation_timeout, session_timeout);
+ co = connection_create(cl, operation_timeout, session_timeout,
+ iochan_man);
}
}
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);
}
// 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;
host->connections = 0;
host->ipport = 0;
- if (host_getaddrinfo(host))
+ if (host_getaddrinfo(host, iochan_man))
{
xfree(host->hostport);
xfree(host);
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)
{
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;
}
{
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)
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
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;
{
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 =
{
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 */
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;
// 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
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 */
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;
}
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;
}
{
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);
}
}
{
struct database *db = new_database(id, se->session_nmem);
- resolve_database(db);
+ resolve_database(se->service, db);
session_init_databases_fun((void*) se, db);
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)
{
struct conf_config *config = (struct conf_config *) data;
- config_start_databases(config);
-
- pazpar2_event_loop();
+ config_process_events(config);
config_destroy(config);
}
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);
{
NMEM nmem; /* for conf_config and servers memory */
struct conf_server *servers;
+
int no_threads;
WRBUF confdir;
+ iochan_man_t iochan_man;
};
server->mergekey_pct = 0;
server->server_settings = 0;
server->http_server = 0;
+ server->iochan_man = 0;
if (server_id)
{
config->nmem = nmem;
config->servers = 0;
config->no_threads = 0;
+ config->iochan_man = 0;
config->confdir = wrbuf_alloc();
if ((p = strrchr(fname,
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)
}
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);
struct conf_server *next;
struct conf_config *config;
http_server_t http_server;
+ iochan_man_t iochan_man;
};
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);
void expand_settings_array(struct setting ***set_ar, int *num, int offset,
NMEM nmem);
-void pazpar2_chan_man_start(int no_threads);
-
#endif
/*