Further work
[pazpar2-moved-to-github.git] / src / connection.c
index c5fb671..fbdaf79 100644 (file)
@@ -246,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);
-        }
     }
 }
 
@@ -336,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);
@@ -426,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