Add <fulltexturl> to sample input record.
[pazpar2-moved-to-github.git] / src / session.c
index d388016..6dce5d9 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2011 Index Data
+   Copyright (C) 2006-2012 Index Data
 
 Pazpar2 is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -523,13 +523,14 @@ static void select_targets_callback(struct session *se,
     {
         cl = client_create(db->database->id);
         client_set_database(cl, db);
-        client_set_session(cl, se);
 
         l = xmalloc(sizeof(*l));
         l->client = cl;
         l->next = se->clients_cached;
         se->clients_cached = l;
     }
+    /* set session always. If may be 0 if client is not active */
+    client_set_session(cl, se);
 
     l = xmalloc(sizeof(*l));
     l->client = cl;
@@ -550,6 +551,11 @@ static void session_reset_active_clients(struct session *se,
     while (l)
     {
         struct client_list *l_next = l->next;
+
+        client_lock(l->client); 
+        client_set_session(l->client, 0); /* mark client inactive */
+        client_unlock(l->client);
+
         xfree(l);
         l = l_next;
     }
@@ -642,11 +648,9 @@ void session_sort(struct session *se, const char *field, int increasing)
     for (l = se->clients_active; l; l = l->next)
     {
         struct client *cl = l->client;
-        struct timeval tval;
-        if (client_prep_connection(cl, se->service->z3950_operation_timeout,
-                                   se->service->z3950_session_timeout,
-                                   se->service->server->iochan_man,
-                                   &tval))
+        if (client_get_state(cl) == Client_Connecting ||
+            client_get_state(cl) == Client_Idle ||
+            client_get_state(cl) == Client_Working)
             client_start_search(cl);
     }
     session_leave(se);
@@ -731,27 +735,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 if (r)
+            {
+                session_log(se, YLOG_LOG, "client NEW %s", client_get_id(cl));
+                client_start_search(cl);
+            }
+            no_working++;
         }
     }
     facet_limits_destroy(facet_limits);
@@ -1920,7 +1921,7 @@ void session_log(struct session *s, int level, const char *fmt, ...)
     va_start(ap, fmt);
 
     yaz_vsnprintf(buf, sizeof(buf)-30, fmt, ap);
-    yaz_log(level, "Session (%u): %s", s->session_id, buf);
+    yaz_log(level, "Session %u: %s", s->session_id, buf);
 
     va_end(ap);
 }