ZOOM: resultsets not ref counted by connections
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 7 May 2010 22:25:09 +0000 (00:25 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 7 May 2010 22:25:09 +0000 (00:25 +0200)
Experimental code and revert to old behavior of result sets.
ZOOM result sets are no longer ref counted by connections: it makes
it very difficult to work with multiple result sets within one
connection because connection would have to be destroyed before all
its result sets are destroyed. It will also makes use of more result
sets IDs on server than we need to  - because ALL result sets in use
will be still available (despite that ZOOM_resultset_destroy is
called). This commit reverts to existing behavior: a result set is
destroyed If ZOOM_resultset_destroy is used AND all operations on it
are completed.

src/zoom-c.c
src/zoom-p.h

index e662615..4091949 100644 (file)
@@ -796,13 +796,18 @@ static zoom_ret do_write(ZOOM_connection c);
 ZOOM_API(void)
     ZOOM_connection_destroy(ZOOM_connection c)
 {
+#if ZOOM_RESULT_LISTS
     ZOOM_resultsets list;
+#else
+    ZOOM_resultset r;
+#endif
     if (!c)
         return;
     yaz_log(log_api, "%p ZOOM_connection_destroy", c);
     if (c->cs)
         cs_close(c->cs);
 
+#if ZOOM_RESULT_LISTS
     // Remove the connection's usage of resultsets
     list = c->resultsets;
     while (list) {
@@ -811,6 +816,10 @@ ZOOM_API(void)
         list = list->next;
         xfree(removed);
     }
+#else
+    for (r = c->resultsets; r; r = r->next)
+        r->connection = 0;
+#endif
 
     xfree(c->buf_in);
     xfree(c->addinfo);
@@ -906,7 +915,9 @@ ZOOM_API(ZOOM_resultset)
     const char *cp;
     int start, count;
     const char *syntax, *elementSetName;
+#if ZOOM_RESULT_LISTS
     ZOOM_resultsets set;
+#endif
 
     yaz_log(log_api, "%p ZOOM_connection_search set %p query %p", c, r, q);
     r->r_sort_spec = q->sort_spec;
@@ -935,13 +946,17 @@ ZOOM_API(ZOOM_resultset)
     
     r->connection = c;
 
+#if ZOOM_RESULT_LISTS
     yaz_log(log_details, "%p ZOOM_connection_search: Adding new resultset (%p) to resultsets (%p) ", c, r, c->resultsets);
     set = xmalloc(sizeof(*set));
     ZOOM_resultset_addref(r);
     set->resultset = r;
     set->next = c->resultsets;
     c->resultsets = set;
-
+#else
+    r->next = c->resultsets;
+    c->resultsets = r;
+#endif
     if (c->host_port && c->proto == PROTO_HTTP)
     {
         if (!c->cs)
@@ -1091,6 +1106,24 @@ static void resultset_destroy(ZOOM_resultset r)
 
         yaz_log(log_details, "%p ZOOM_connection resultset_destroy: Deleting resultset (%p) ", r->connection, r);
         ZOOM_resultset_cache_reset(r);
+#if ZOOM_RESULT_LISTS
+#else
+        if (r->connection)
+        {
+            /* remove ourselves from the resultsets in connection */
+            ZOOM_resultset *rp = &r->connection->resultsets;
+            while (1)
+            {
+                assert(*rp);   /* we must be in this list!! */
+                if (*rp == r)
+                {   /* OK, we're here - take us out of it */
+                    *rp = (*rp)->next;
+                    break;
+                }
+                rp = &(*rp)->next;
+            }
+        }
+#endif
         ZOOM_query_destroy(r->query);
         ZOOM_options_destroy(r->options);
         odr_destroy(r->odr);
@@ -1762,6 +1795,7 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c)
                result sets on the server. */
             for (ord = 1; ; ord++)
             {
+#if ZOOM_RESULT_LISTS
                 ZOOM_resultsets rsp;
                 sprintf(setname, "%d", ord);
                 for (rsp = c->resultsets; rsp; rsp = rsp->next)
@@ -1769,6 +1803,16 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c)
                         break;
                 if (!rsp)
                     break;
+#else
+                ZOOM_resultset rp;
+                sprintf(setname, "%d", ord);
+                for (rp = c->resultsets; rp; rp = rp->next)
+                    if (rp->setname && !strcmp(rp->setname, setname))
+                        break;
+                if (!rp)
+                    break;
+#endif
+
             }
             r->setname = xstrdup(setname);
             yaz_log(log_details, "%p ZOOM_connection_send_search: allocating "
index 05f5503..844badf 100644 (file)
@@ -38,6 +38,7 @@
 #include <yaz/mutex.h>
 
 #define SHPTR 1
+#define ZOOM_RESULT_LISTS 0
 
 typedef struct ZOOM_Event_p *ZOOM_Event;
 
@@ -63,7 +64,9 @@ typedef struct ZOOM_task_p *ZOOM_task;
 #define STATE_CONNECTING 1
 #define STATE_ESTABLISHED 2
 
+#if ZOOM_RESULT_LISTS
 typedef struct ZOOM_resultsets_p *ZOOM_resultsets;
+#endif
 
 struct ZOOM_connection_p {
     enum oid_proto proto;
@@ -104,18 +107,23 @@ struct ZOOM_connection_p {
 
     ZOOM_task tasks;
     ZOOM_options options;
+#if ZOOM_RESULT_LISTS
     ZOOM_resultsets resultsets;
+#else
+    ZOOM_resultset resultsets;
+#endif
     ZOOM_Event m_queue_front;
     ZOOM_Event m_queue_back;
     zoom_sru_mode sru_mode;
     int no_redirects; /* 0 for no redirects. >0 for number of redirects */
 };
 
+#if ZOOM_RESULT_LISTS
 struct ZOOM_resultsets_p {
     ZOOM_resultset resultset;
     ZOOM_resultsets next;
 };
-
+#endif
 
 struct ZOOM_options_entry {
     char *name;
@@ -157,6 +165,10 @@ struct ZOOM_resultset_p {
 #if SHPTR
     struct WRBUF_shptr *record_wrbuf;
 #endif
+#if ZOOM_RESULT_LISTS
+#else
+    ZOOM_resultset next;
+#endif
 };
 
 struct ZOOM_record_p {