X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fconnection.c;h=fbdaf797b19a0795677b5bb7b0acc485bea80f5f;hb=24ad8ea356d71c764af19897e2719670a94a3a05;hp=2c7c0c215e7b6a95be661f028dfb7a32f49a685e;hpb=e9e5603afa14e52f004d64211345f1c3ab17a6a3;p=pazpar2-moved-to-github.git diff --git a/src/connection.c b/src/connection.c index 2c7c0c2..fbdaf79 100644 --- a/src/connection.c +++ b/src/connection.c @@ -144,6 +144,7 @@ static struct connection *connection_create(struct client *cl, iochan_man_t iochan_man) { struct connection *co; + int ret; co = xmalloc(sizeof(*co)); @@ -159,9 +160,13 @@ static struct connection *connection_create(struct client *cl, co->operation_timeout = operation_timeout; co->session_timeout = session_timeout; - connection_connect(co, iochan_man); - + ret = connection_connect(co, iochan_man); connection_use(1); + if (ret) + { /* error */ + connection_destroy(co); + co = 0; + } return co; } @@ -241,10 +246,7 @@ static void non_block_events(struct connection *co) { struct client *cl = co->client; if (cl) - { - client_check_preferred_watch(cl); client_got_records(cl); - } } } @@ -318,6 +320,11 @@ static void connection_handler(IOCHAN iochan, int event) } } +void connection_release2(struct connection *co) +{ + co->client = 0; +} + static int connection_connect(struct connection *con, iochan_man_t iochan_man) { ZOOM_options zoptions = ZOOM_options_create(); @@ -326,6 +333,7 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man) const char *sru; const char *sru_version = 0; const char *value; + int r = 0; WRBUF w; struct session_database *sdb = client_get_database(con->client); @@ -416,12 +424,22 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man) con->state = Conn_Connecting; iochan_settimeout(con->iochan, con->operation_timeout); iochan_setdata(con->iochan, con); - iochan_add(iochan_man, con->iochan); - - client_set_state(con->client, Client_Connecting); + if (iochan_add(iochan_man, con->iochan)) + { + yaz_log(YLOG_FATAL, "Out of connections"); + iochan_destroy(con->iochan); + con->iochan = 0; + ZOOM_connection_destroy(con->link); + con->link = 0; + r = -1; + } + else + { + client_set_state(con->client, Client_Connecting); + } ZOOM_options_destroy(zoptions); wrbuf_destroy(w); - return 0; + return r; } // Ensure that client has a connection associated @@ -445,6 +463,8 @@ int client_prep_connection(struct client *cl, client_get_id(cl), url); co = client_get_connection(cl); + if (co) + return 2; if (!co) { co = connection_create(cl, url, zproxy,