Simplify ZURL resolving and use regular getaddrinfo
[pazpar2-moved-to-github.git] / src / connection.c
index c4dfe72..219380c 100644 (file)
@@ -52,14 +52,15 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 static YAZ_MUTEX g_mutex = 0;
 static int no_connections = 0;
 static int total_no_connections = 0;
-static void connection_use(int delta)
+
+static int connection_use(int delta)
 {
     int result;
     if (!g_mutex)
         yaz_mutex_create(&g_mutex);
     yaz_mutex_enter(g_mutex);
     no_connections += delta;
-    result = no_connection;
+    result = no_connections;
     if (delta > 0)
         total_no_connections += delta;
     yaz_mutex_leave(g_mutex);
@@ -70,7 +71,8 @@ static void connection_use(int delta)
     return result;
 }
 
-int connections_count() {
+int connections_count(void)
+{
     return connection_use(0);
 }
 
@@ -181,8 +183,8 @@ static struct connection *connection_create(struct client *cl,
     co->state = Conn_Resolving;
     co->operation_timeout = operation_timeout;
     co->session_timeout = session_timeout;
-    if (host->ipport)
-        connection_connect(co, iochan_man);
+    
+    connection_connect(co, iochan_man);
 
     yaz_mutex_enter(host->mutex);
     co->next = co->host->connections;
@@ -350,50 +352,6 @@ static void connection_release(struct connection *co)
     co->client = 0;
 }
 
-void connect_resolver_host(struct host *host, iochan_man_t iochan_man)
-{
-    struct connection *con;
-
-start:
-    yaz_mutex_enter(host->mutex);
-    con = host->connections;
-    while (con)
-    {
-        if (con->state == Conn_Resolving)
-        {
-            if (!host->ipport) /* unresolved */
-            {
-                remove_connection_from_host(con);
-                yaz_mutex_leave(host->mutex);
-                connection_destroy(con);
-                goto start;
-                /* start all over .. at some point it will be NULL */
-            }
-            else if (!con->client)
-            {
-                remove_connection_from_host(con);
-                yaz_mutex_leave(host->mutex);
-                connection_destroy(con);
-                /* start all over .. at some point it will be NULL */
-                goto start;
-            }
-            else
-            {
-                yaz_mutex_leave(host->mutex);
-                connection_connect(con, iochan_man);
-                client_start_search(con->client);
-                goto start;
-            }
-        }
-        else
-        {
-            yaz_log(YLOG_LOG, "connect_resolver_host: state=%d", con->state);
-            con = con->next;
-        }
-    }
-    yaz_mutex_leave(host->mutex);
-}
-
 static struct host *connection_get_host(struct connection *con)
 {
     return con->host;
@@ -413,7 +371,6 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man)
     const char *zproxy = session_setting_oneval(sdb, PZ_ZPROXY);
     const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG);
 
-    assert(host->ipport);
     assert(con);
 
     ZOOM_options_set(zoptions, "async", "1");
@@ -452,10 +409,10 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man)
         strcat(http_hostport, host->hostport);
         ZOOM_connection_connect(link, http_hostport, 0);
     }
-    else if (zproxy && *zproxy)
-        ZOOM_connection_connect(link, host->hostport, 0);        
     else
-        ZOOM_connection_connect(link, host->ipport, 0);
+    {
+        ZOOM_connection_connect(link, host->hostport, 0);
+    }
     
     con->link = link;
     con->iochan = iochan_create(-1, connection_handler, 0, "connection_socket");