Happy new year
[pazpar2-moved-to-github.git] / src / http_command.c
index a905750..bdd68a8 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2010 Index Data
+   Copyright (C) 2006-2011 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
@@ -109,7 +109,7 @@ struct http_session *http_session_create(struct conf_service *service,
     char tmp_str[50];
 
     sprintf(tmp_str, "session#%u", sesid);
-    r->psession = new_session(nmem, service, tmp_str);
+    r->psession = new_session(nmem, service, sesid);
     r->session_id = sesid;
     r->timestamp = 0;
     r->nmem = nmem;
@@ -936,7 +936,19 @@ static void cmd_show(struct http_channel *c)
 
     if (block)
     {
-        if (status && reclist_get_num_records(s->psession->reclist) == 0)
+        if (!strcmp(block, "preferred") && !session_is_preferred_clients_ready(s->psession) && reclist_get_num_records(s->psession->reclist) == 0) {
+            // if there is already a watch/block. we do not block this one
+            if (session_set_watch(s->psession, SESSION_WATCH_SHOW_PREF,
+                                  show_records_ready, c, c) != 0)
+            {
+                yaz_log(c->http_sessions->log_level,
+                        "%p Session %u: Blocking on cmd_show. Waiting for preferred targets", s, s->session_id);
+            }
+            release_session(c,s);
+            return;
+
+        }
+        else if (status && reclist_get_num_records(s->psession->reclist) == 0)
         {
             // if there is already a watch/block. we do not block this one
             if (session_set_watch(s->psession, SESSION_WATCH_SHOW,