Remove connection_freelist
[pazpar2-moved-to-github.git] / src / connection.c
index f318378..80ba36b 100644 (file)
@@ -55,8 +55,6 @@ struct connection {
     ZOOM_connection link;
     struct host *host;
     struct client *client;
-    char *ibuf;
-    int ibufsize;
     char *zproxy;
     enum {
         Conn_Resolving,
@@ -68,9 +66,7 @@ struct connection {
     struct connection *next; // next for same host or next in free list
 };
 
-static struct connection *connection_freelist = 0;
-
-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)
 {
@@ -126,28 +122,20 @@ void connection_destroy(struct connection *co)
         client_disconnect(co->client);
     }
     xfree(co->zproxy);
-    co->zproxy = 0;
-    co->next = connection_freelist;
-    connection_freelist = co;
+    xfree(co);
 }
 
 // Creates a new connection for client, associated with the host of 
 // 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);
 
-    if ((new = connection_freelist))
-        connection_freelist = new->next;
-    else
-    {
-        new = xmalloc(sizeof (struct connection));
-        new->ibuf = 0;
-        new->ibufsize = 0;
-    }
+    new = xmalloc(sizeof(*new));
     new->host = host;
     new->next = new->host->connections;
     new->host->connections = new;
@@ -159,7 +147,7 @@ static struct connection *connection_create(struct client *cl,
     new->operation_timeout = operation_timeout;
     new->session_timeout = session_timeout;
     if (host->ipport)
-        connection_connect(new);
+        connection_connect(new, iochan_man);
     return new;
 }
 
@@ -278,7 +266,7 @@ void connection_release(struct connection *co)
     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)
@@ -301,7 +289,7 @@ void connect_resolver_host(struct host *host)
             }
             else
             {
-                connection_connect(con);
+                connection_connect(con, iochan_man);
                 client_start_search(con->client);
             }
         }
@@ -340,7 +328,7 @@ static int maskfun(IOCHAN c)
     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);
@@ -404,7 +392,7 @@ static int connection_connect(struct connection *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);
@@ -419,7 +407,8 @@ const char *connection_get_url(struct connection *co)
 
 // 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);
@@ -466,7 +455,8 @@ int client_prep_connection(struct client *cl,
         }
         else
         {
-            co = connection_create(cl, operation_timeout, session_timeout);
+            co = connection_create(cl, operation_timeout, session_timeout,
+                                   iochan_man);
         }
     }