command=stop functional and works much better PAZ-967
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 17 Sep 2014 12:44:20 +0000 (14:44 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 29 Sep 2014 11:56:09 +0000 (13:56 +0200)
src/client.c
src/client.h
src/connection.c
src/connection.h
src/http_command.c
src/session.c
src/session.h

index 9af8c2b..60553fd 100644 (file)
@@ -927,6 +927,8 @@ int client_start_search(struct client *cl)
     int present_chunk = 20; // Default chunk size
     int rc_prep_connection;
 
+    cl->diagnostic = 0;
+    cl->record_failures = cl->ingest_failures = cl->filtered = 0;
 
     yaz_gettimeofday(&tval);
     tval.tv_sec += 5;
@@ -961,9 +963,6 @@ int client_start_search(struct client *cl)
 
     session_log(se, YLOG_LOG, "%s: new search", client_get_id(cl));
 
-    cl->diagnostic = 0;
-    cl->record_failures = cl->ingest_failures = cl->filtered = 0;
-
     client_destroy_xdoc(cl);
     client_init_xdoc(cl);
 
@@ -1165,6 +1164,26 @@ void client_disconnect(struct client *cl)
     client_set_connection(cl, 0);
 }
 
+void client_stop(struct client *cl)
+{
+    client_lock(cl);
+    if (cl->state == Client_Working || cl->state == Client_Connecting)
+    {
+        yaz_log(YLOG_LOG, "client_stop: %s release", client_get_id(cl));
+        if (cl->connection)
+        {
+            connection_release2(cl->connection);
+            assert(cl->ref_count > 1);
+            cl->ref_count--;
+            cl->connection = 0;
+        }
+        cl->state = Client_Disconnected;
+    }
+    else
+        yaz_log(YLOG_LOG, "client_stop: %s ignore", client_get_id(cl));
+    client_unlock(cl);
+}
+
 // Initialize CCL map for a target
 static CCL_bibset prepare_cclmap(struct client *cl, CCL_bibset base_bibset)
 {
index 5d8bace..6092dfa 100644 (file)
@@ -101,6 +101,7 @@ void client_incref(struct client *c);
 void client_got_records(struct client *c);
 void client_lock(struct client *c);
 void client_unlock(struct client *c);
+void client_stop(struct client *c);
 
 int client_has_facet(struct client *cl, const char *name);
 void client_check_preferred_watch(struct client *cl);
index df01303..c52fcf3 100644 (file)
@@ -360,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;
index e92019e..1b7b24c 100644 (file)
@@ -34,6 +34,7 @@ void connect_resolver_host(struct host *host, iochan_man_t iochan);
 ZOOM_connection connection_get_link(struct connection *co);
 void connection_continue(struct connection *co);
 void connect_resolver_host(struct host *host, iochan_man_t iochan_man);
+void connection_release2(struct connection *co);
 
 #endif
 
index 309a617..7c23404 100644 (file)
@@ -1457,6 +1457,17 @@ static void cmd_stat(struct http_channel *c)
     release_session(c, s);
 }
 
+static void cmd_stop(struct http_channel *c)
+{
+    struct http_session *s = locate_session(c);
+    if (!s)
+        return;
+    response_open_ok(c, "stop");
+    session_stop(s->psession);
+    response_close(c, "stop");
+    release_session(c, s);
+}
+
 static void cmd_info(struct http_channel *c)
 {
     char yaz_version_str[20];
@@ -1516,6 +1527,7 @@ struct {
     { "ping", cmd_ping },
     { "record", cmd_record },
     { "info", cmd_info },
+    { "stop", cmd_stop },
     {0,0}
 };
 
index fb895de..ff0e038 100644 (file)
@@ -726,6 +726,33 @@ void session_sort(struct session *se, struct reclist_sortparms *sp,
     }
 }
 
+void session_stop(struct session *se)
+{
+    struct client_list *l;
+    session_enter(se, "session_stop1");
+    if (se->clients_starting)
+    {
+        session_leave(se, "session_stop1");
+        return;
+    }
+    se->clients_starting = 1;
+    session_leave(se, "session_stop1");
+
+    session_alert_watch(se, SESSION_WATCH_SHOW);
+    session_alert_watch(se, SESSION_WATCH_BYTARGET);
+    session_alert_watch(se, SESSION_WATCH_TERMLIST);
+    session_alert_watch(se, SESSION_WATCH_SHOW_PREF);
+
+    for (l = se->clients_active; l; l = l->next)
+    {
+        struct client *cl = l->client;
+        client_stop(cl);
+    }
+    session_enter(se, "session_stop2");
+    se->clients_starting = 0;
+    session_leave(se, "session_stop2");
+}
+
 enum pazpar2_error_code session_search(struct session *se,
                                        const char *query,
                                        const char *startrecs,
index 76786f4..ecc5549 100644 (file)
@@ -186,6 +186,7 @@ int session_is_preferred_clients_ready(struct session *s);
 void session_apply_setting(struct session *se, const char *dbname,
                            const char *setting, const char *value);
 const char *session_setting_oneval(struct session_database *db, int offset);
+void session_stop(struct session *se);
 
 int ingest_record(struct client *cl, const char *rec, int record_no, NMEM nmem);
 int ingest_xml_record(struct client *cl, xmlDoc *xdoc,