42 #include <yaz/comstack.h>
43 #include <yaz/tcpip.h>
69 yaz_log(YLOG_LOG,
"%s connections=%d", delta > 0 ?
"INC" :
"DEC",
81 #define connection_use(x)
82 #define connections_count(x) 0
83 #define connections_count_total(x) 0
115 if (!ZOOM_connection_is_idle(link))
117 event = ZOOM_connection_peek_event(link);
118 if (event == ZOOM_EVENT_NONE)
137 *conp = (*conp)->
next;
140 conp = &(*conp)->
next;
150 ZOOM_connection_destroy(co->
link);
153 yaz_log(YLOG_DEBUG,
"%p Connection destroy %s", co, co->
host->
url);
175 co = xmalloc(
sizeof(*co));
189 yaz_mutex_enter(host->
mutex);
192 yaz_mutex_leave(host->
mutex);
207 int r = ZOOM_event_nonblock(1, &link);
212 ev = ZOOM_connection_last_event(link);
215 yaz_log(YLOG_DEBUG,
"%p Connection ZOOM_EVENT_%s", co, ZOOM_get_event_str(ev));
219 case ZOOM_EVENT_TIMEOUT:
225 if ((err = ZOOM_connection_error(link, &error, &addinfo)))
227 yaz_log(YLOG_LOG,
"Error %s from %s",
240 case ZOOM_EVENT_SEND_DATA:
242 case ZOOM_EVENT_RECV_DATA:
244 case ZOOM_EVENT_UNKNOWN:
246 case ZOOM_EVENT_SEND_APDU:
250 case ZOOM_EVENT_RECV_APDU:
252 case ZOOM_EVENT_CONNECT:
254 co->
state = Conn_Open;
256 case ZOOM_EVENT_RECV_SEARCH:
259 case ZOOM_EVENT_RECV_RECORD:
263 yaz_log(YLOG_LOG,
"Unhandled event (%d) from %s",
281 int r = ZOOM_connection_exec_task(co->
link);
297 yaz_mutex_enter(host->
mutex);
304 yaz_log(YLOG_LOG,
"timeout connection %p event=%d", co, event);
306 yaz_mutex_leave(host->
mutex);
311 ZOOM_connection_fire_event_timeout(co->
link);
317 yaz_mutex_leave(host->
mutex);
322 yaz_mutex_leave(host->
mutex);
327 ZOOM_connection_fire_event_socket(co->
link, event);
357 yaz_mutex_enter(host->
mutex);
366 yaz_mutex_leave(host->
mutex);
374 yaz_mutex_leave(host->
mutex);
381 yaz_mutex_leave(host->
mutex);
389 yaz_log(YLOG_LOG,
"connect_resolver_host: state=%d", con->
state);
393 yaz_mutex_leave(host->
mutex);
404 ZOOM_options zoptions = ZOOM_options_create();
408 const char *sru_version = 0;
415 ZOOM_options_set(zoptions,
"async",
"1");
416 ZOOM_options_set(zoptions,
"implementationName",
PACKAGE_NAME);
417 ZOOM_options_set(zoptions,
"implementationVersion",
VERSION);
420 ZOOM_options_set(zoptions,
"charset", charset);
425 yaz_log(YLOG_LOG,
"proxy=%s", host->
ipport);
426 ZOOM_options_set(zoptions,
"proxy", host->
ipport);
431 yaz_log(YLOG_LOG,
"tproxy=%s", host->
ipport);
432 ZOOM_options_set(zoptions,
"tproxy", host->
ipport);
435 if (apdulog && *apdulog)
436 ZOOM_options_set(zoptions,
"apdulog", apdulog);
439 ZOOM_options_set(zoptions,
"user", auth);
441 ZOOM_options_set(zoptions,
"sru", sru);
444 ZOOM_options_set(zoptions,
"sru_version", sru_version);
445 if (!(con->
link = ZOOM_connection_create(zoptions)))
447 yaz_log(YLOG_FATAL|YLOG_ERRNO,
"Failed to create ZOOM Connection");
448 ZOOM_options_destroy(zoptions);
452 if (sru && *sru && !strstr(host->
url,
"://"))
454 WRBUF w = wrbuf_alloc();
455 wrbuf_puts(w,
"http://");
456 wrbuf_puts(w, host->
url);
457 ZOOM_connection_connect(con->
link, wrbuf_cstr(w), 0);
462 ZOOM_connection_connect(con->
link, host->
url, 0);
465 con->
state = Conn_Connecting;
471 ZOOM_options_destroy(zoptions);
479 const struct timeval *abstime)
487 int default_port = *sru ? 80 : 210;
489 if (zproxy && zproxy[0] ==
'\0')
496 url, zproxy, default_port, iochan_man);
498 yaz_log(YLOG_DEBUG,
"client_prep_connection: target=%s url=%s",
518 int max_connections = 0;
519 int reuse_connections = 1;
523 max_connections = atoi(v);
528 reuse_connections = atoi(v);
532 yaz_mutex_enter(host->
mutex);
535 int num_connections = 0;
538 if (reuse_connections)
544 !strcmp(ZOOM_connection_option_get(co->
link,
"user"),
548 if (zproxy == 0 && co->
zproxy == 0)
550 if (zproxy && co->
zproxy && !strcmp(zproxy, co->
zproxy))
556 yaz_log(YLOG_LOG,
"num_connections = %d (reusing)", num_connections);
560 if (max_connections <= 0 || num_connections < max_connections)
562 yaz_log(YLOG_LOG,
"num_connections = %d (new); max = %d",
563 num_connections, max_connections);
566 yaz_log(YLOG_LOG,
"num_connections = %d (waiting) max = %d",
567 num_connections, max_connections);
570 yaz_log(YLOG_LOG,
"out of connections %s",
client_get_id(cl));
572 yaz_mutex_leave(host->
mutex);
578 yaz_log(YLOG_LOG,
"%p Connection reuse. state: %d", co, co->
state);
585 yaz_mutex_leave(host->
mutex);
590 ZOOM_connection_connect(co->
link, 0, 0);
594 yaz_mutex_leave(host->
mutex);