Merge branch 'master' of ssh://git.indexdata.com/home/git/pub/pazpar2
[pazpar2-moved-to-github.git] / src / client.c
index c238f0a..b3500de 100644 (file)
@@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #if HAVE_CONFIG_H
 #include <config.h>
 #endif
-#include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -79,7 +78,7 @@ static void client_use(int delta)
     yaz_mutex_enter(g_mutex);
     no_clients += delta;
     yaz_mutex_leave(g_mutex);
-    yaz_log(YLOG_LOG, "%s clients=%d", delta > 0 ? "INC" : "DEC", no_clients);
+    yaz_log(YLOG_DEBUG, "%s clients=%d", delta > 0 ? "INC" : "DEC", no_clients);
 }
 #else
 #define client_use(x)
@@ -140,14 +139,12 @@ void client_set_state(struct client *cl, enum client_state st)
     cl->state = st;
     /* no need to check for all client being non-active if this one
        already is. Note that session_active_clients also LOCKS session */
-#if 0
     if (!client_is_active(cl) && cl->session)
     {
         int no_active = session_active_clients(cl->session);
         if (no_active == 0)
             session_alert_watch(cl->session, SESSION_WATCH_SHOW);
     }
-#endif
 }
 
 static void client_show_raw_error(struct client *cl, const char *addinfo);
@@ -639,7 +636,7 @@ void client_unlock(struct client *c)
 void client_incref(struct client *c)
 {
     pazpar2_incref(&c->ref_count, c->mutex);
-    yaz_log(YLOG_LOG, "client_incref c=%p %s cnt=%d",
+    yaz_log(YLOG_DEBUG, "client_incref c=%p %s cnt=%d",
             c, client_get_url(c), c->ref_count);
 }
 
@@ -647,7 +644,7 @@ int client_destroy(struct client *c)
 {
     if (c)
     {
-        yaz_log(YLOG_LOG, "client_destroy c=%p %s cnt=%d",
+        yaz_log(YLOG_DEBUG, "client_destroy c=%p %s cnt=%d",
                 c, client_get_url(c), c->ref_count);
         if (!pazpar2_decref(&c->ref_count, c->mutex))
         {
@@ -656,8 +653,11 @@ int client_destroy(struct client *c)
             xfree(c->cqlquery);
             c->cqlquery = 0;
             assert(!c->connection);
-            assert(!c->resultset);
-            
+
+            if (c->resultset)
+            {
+                ZOOM_resultset_destroy(c->resultset);
+            }
             yaz_mutex_destroy(&c->mutex);
             xfree(c);
             client_use(-1);
@@ -670,10 +670,7 @@ int client_destroy(struct client *c)
 void client_set_connection(struct client *cl, struct connection *con)
 {
     if (cl->resultset)
-    {
-        ZOOM_resultset_destroy(cl->resultset);
-        cl->resultset = 0;
-    }
+        ZOOM_resultset_release(cl->resultset);
     if (con)
     {
         assert(cl->connection == 0);
@@ -818,6 +815,7 @@ int client_parse_query(struct client *cl, const char *query)
     else
         cl->cqlquery = 0;
 
+    /* TODO FIX Not thread safe */
     if (!se->relevance)
     {
         // Initialize relevance structure with query terms