Release record block on show after first chunk
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 11 Mar 2010 11:41:59 +0000 (12:41 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 11 Mar 2010 11:41:59 +0000 (12:41 +0100)
The client and connection code now fires SESSION_WATCH_SHOW and
SESSION_WATCH_RECORD after all non-blocking events has been received
from some client. Previously this was done on first record received.
Fixes #3318.

src/client.c
src/client.h
src/connection.c

index b4d323e..7e1645a 100644 (file)
@@ -417,6 +417,15 @@ void client_search_response(struct client *cl)
     }
 }
 
+void client_got_records(struct client *cl)
+{
+    if (cl->session)
+    {
+        session_alert_watch(cl->session, SESSION_WATCH_SHOW);
+        session_alert_watch(cl->session, SESSION_WATCH_RECORD);
+    }
+}
+
 void client_record_response(struct client *cl)
 {
     struct connection *co = cl->connection;
@@ -478,11 +487,6 @@ void client_record_response(struct client *cl)
                         if (ingest_record(cl, xmlrec, cl->record_offset, nmem))
                             yaz_log(YLOG_WARN, "Failed to ingest from %s",
                                     client_get_url(cl));
-                        else
-                        {
-                            session_alert_watch(cl->session, SESSION_WATCH_SHOW);
-                            session_alert_watch(cl->session, SESSION_WATCH_RECORD);
-                        }
                     }
                     nmem_destroy(nmem);
                 }
index 7eedec8..e746efa 100644 (file)
@@ -91,7 +91,7 @@ void client_set_maxrecs(struct client *cl, int v);
 void client_set_startrecs(struct client *cl, int v);
 void client_remove_from_session(struct client *c);
 void client_incref(struct client *c);
-
+void client_got_records(struct client *c);
 #endif
 
 /*
index 3fb061b..1525dfb 100644 (file)
@@ -159,6 +159,7 @@ static struct connection *connection_create(struct client *cl,
 
 static void non_block_events(struct connection *co)
 {
+    int got_records = 0;
     IOCHAN iochan = co->iochan;
     ZOOM_connection link = co->link;
     while (1)
@@ -213,6 +214,7 @@ static void non_block_events(struct connection *co)
             break;
         case ZOOM_EVENT_RECV_RECORD:
             client_record_response(cl);
+            got_records = 1;
             break;
         default:
             yaz_log(YLOG_LOG, "Unhandled event (%d) from %s",
@@ -220,6 +222,16 @@ static void non_block_events(struct connection *co)
         }
         client_destroy(cl);
     }
+    if (got_records)
+    {
+        struct client *cl = co->client;
+        if (cl)
+        {
+            client_incref(cl); 
+            client_got_records(cl);
+            client_destroy(cl);
+        }
+    }
 }
 
 void connection_continue(struct connection *co)