Pass -1 as no-socket parameter to iochan_create
[pazpar2-moved-to-github.git] / src / database.c
index 6f1599a..da26ed0 100644 (file)
@@ -27,9 +27,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <yaz/log.h>
+#include <yaz/nmem.h>
 
-#include "pazpar2.h"
+#include "ppmutex.h"
+#include "session.h"
 #include "host.h"
+#include "pazpar2_config.h"
 #include "settings.h"
 #include "http.h"
 #include "zeerex.h"
@@ -107,7 +110,9 @@ static struct host *create_host(const char *hostport, iochan_man_t iochan_man)
         xfree(host);
         return 0;
     }
-    yaz_mutex_create(&host->mutex);
+    pazpar2_mutex_create(&host->mutex, "host");
+
+    yaz_cond_create(&host->cond_ready);
 
     return host;
 }
@@ -182,7 +187,7 @@ struct database *new_database(const char *id, NMEM nmem)
     db->errors = 0;
     db->explain = 0;
 
-    db->num_settings = PZ_NEGOTIATION_CHARSET+1;
+    db->num_settings = PZ_MAX_EOF;
     db->settings = nmem_malloc(nmem, sizeof(struct settings*) * 
                                db->num_settings);
     memset(db->settings, 0, sizeof(struct settings*) * db->num_settings);
@@ -408,10 +413,30 @@ database_hosts_t database_hosts_create(void)
     database_hosts_t p = xmalloc(sizeof(*p));
     p->hosts = 0;
     p->mutex = 0;
-    yaz_mutex_create(&p->mutex);
+    pazpar2_mutex_create(&p->mutex, "database");
     return p;
 }
 
+void database_hosts_destroy(database_hosts_t *pp)
+{
+    if (*pp)
+    {
+        struct host *p = (*pp)->hosts;
+        while (p)
+        {
+            struct host *p_next = p->next;
+            yaz_mutex_destroy(&p->mutex);
+            yaz_cond_destroy(&p->cond_ready);
+            xfree(p->ipport);
+            xfree(p->hostport);
+            xfree(p);
+            p = p_next;
+        }
+        yaz_mutex_destroy(&(*pp)->mutex);
+        xfree(*pp);
+    }
+}
+
 /*
  * Local variables:
  * c-basic-offset: 4