command=stop functional and works much better PAZ-967
[pazpar2-moved-to-github.git] / src / connection.c
index 2524434..c52fcf3 100644 (file)
@@ -216,7 +216,7 @@ static void non_block_events(struct connection *co)
         ev = ZOOM_connection_last_event(link);
 
 #if 1
-        yaz_log(YLOG_LOG, "%p Connection ZOOM_EVENT_%s", co, ZOOM_get_event_str(ev));
+        yaz_log(YLOG_DEBUG, "%p Connection ZOOM_EVENT_%s", co, ZOOM_get_event_str(ev));
 #endif
         switch (ev)
         {
@@ -228,8 +228,10 @@ static void non_block_events(struct connection *co)
                 int err;
                 if ((err = ZOOM_connection_error(link, &error, &addinfo)))
                 {
-                    yaz_log(YLOG_LOG, "Error %s from %s",
-                            error, client_get_id(cl));
+                    struct session *se = client_get_session(cl);
+
+                    session_log(se, YLOG_WARN, "%s: Error %s (%s)",
+                                client_get_id(cl), error, addinfo);
                     client_set_diagnostic(cl, err, error, addinfo);
                     client_set_state(cl, Client_Error);
                 }
@@ -254,7 +256,6 @@ static void non_block_events(struct connection *co)
         case ZOOM_EVENT_RECV_APDU:
             break;
         case ZOOM_EVENT_CONNECT:
-            yaz_log(YLOG_LOG, "Connected to %s", client_get_id(cl));
             co->state = Conn_Open;
             break;
         case ZOOM_EVENT_RECV_SEARCH:
@@ -284,7 +285,13 @@ void connection_continue(struct connection *co)
 {
     int r = ZOOM_connection_exec_task(co->link);
     if (!r)
+    {
+        struct client *cl = co->client;
+
+        client_lock(cl);
         non_block_events(co);
+        client_unlock(cl);
+    }
     else
     {
         iochan_setflags(co->iochan, ZOOM_connection_get_mask(co->link));
@@ -353,6 +360,11 @@ static void connection_release(struct connection *co)
     co->client = 0;
 }
 
+void connection_release2(struct connection *co)
+{
+    co->client = 0;
+}
+
 void connect_resolver_host(struct host *host, iochan_man_t iochan_man)
 {
     struct connection *con;
@@ -363,7 +375,8 @@ void connect_resolver_host(struct host *host, iochan_man_t iochan_man)
     {
         if (con->state == Conn_Closed)
         {
-            if (!host->ipport || !con->client) /* unresolved or no client */
+            struct client *cl = con->client;
+            if (!host->ipport || !cl) /* unresolved or no client */
             {
                 remove_connection_from_host(con);
                 yaz_mutex_leave(host->mutex);
@@ -371,11 +384,12 @@ void connect_resolver_host(struct host *host, iochan_man_t iochan_man)
             }
             else
             {
-                struct session_database *sdb = client_get_database(con->client);
-                if (sdb)
+                struct session_database *sdb = client_get_database(cl);
+                struct session *se = client_get_session(cl);
+                if (sdb && se)
                 {
                     yaz_mutex_leave(host->mutex);
-                    client_start_search(con->client);
+                    client_start_search(cl);
                 }
                 else
                 {
@@ -415,6 +429,7 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man)
     struct session_database *sdb = client_get_database(con->client);
     const char *apdulog = session_setting_oneval(sdb, PZ_APDULOG);
     const char *memcached = session_setting_oneval(sdb, PZ_MEMCACHED);
+    const char *redis = session_setting_oneval(sdb, PZ_REDIS);
 
     assert(con);
 
@@ -426,6 +441,8 @@ static int connection_connect(struct connection *con, iochan_man_t iochan_man)
         ZOOM_options_set(zoptions, "charset", charset);
     if (memcached && *memcached)
         ZOOM_options_set(zoptions, "memcached", memcached);
+    if (redis && *redis)
+        ZOOM_options_set(zoptions, "redis", redis);
 
     assert(host->ipport);
     if (host->proxy)