Yet another fix for connection re-use
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 3 Jan 2012 13:03:46 +0000 (14:03 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 3 Jan 2012 13:03:46 +0000 (14:03 +0100)
client_prep_connection returns 2 if connection was re-usable
and only in that case will the result set be re-used - for same
search.

src/connection.c
src/session.c

index f1ca36e..0b7a79b 100644 (file)
@@ -526,13 +526,12 @@ int client_prep_connection(struct client *cl,
     {
         assert(co->host);
         if (co->host == host && client_get_state(cl) == Client_Idle)
-            ;  /* reusing connection. It's ours! */
-        else 
         {
-            client_incref(cl);
-            connection_release(co);
-            co = 0;
+            return 2;
         }
+        client_incref(cl);
+        connection_release(co);
+        co = 0;
     }
     if (!co)
     {
index 19ac45c..425d6ca 100644 (file)
@@ -731,27 +731,24 @@ enum pazpar2_error_code session_search(struct session *se,
             no_failed_query++;
         else if (parse_ret == -2)
             no_failed_limit++;
-        else if (parse_ret == 0)
-        {
-            session_log(se, YLOG_LOG, "client NEW %s", client_get_id(cl));
-            no_working++;
-            if (client_prep_connection(cl, se->service->z3950_operation_timeout,
-                                       se->service->z3950_session_timeout,
-                                       se->service->server->iochan_man,
-                                       &tval))
-                client_start_search(cl);
-        }
         else
         {
-            session_log(se, YLOG_LOG, "client REUSE %s", client_get_id(cl));
-            no_working++;
-            if (client_prep_connection(cl, se->service->z3950_operation_timeout,
+            int r =
+                client_prep_connection(cl, se->service->z3950_operation_timeout,
                                        se->service->z3950_session_timeout,
                                        se->service->server->iochan_man,
-                                       &tval))
+                                       &tval);
+            if (parse_ret == 1 && r == 2)
             {
+                session_log(se, YLOG_LOG, "client REUSE %s", client_get_id(cl));
                 client_reingest(cl);
             }
+            else
+            {
+                session_log(se, YLOG_LOG, "client NEW %s", client_get_id(cl));
+                client_start_search(cl);
+            }
+            no_working++;
         }
     }
     facet_limits_destroy(facet_limits);