Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Tarassov2019-07-18 17:11:12 -0400
committerEugene Tarassov2019-07-18 17:11:12 -0400
commitd26501f1d5533bc9b09220a89caeef1409078106 (patch)
tree9028d92ab795871f7dfed87449065d289bf05254
parentcd009566ed9c65f46b6fa59444a128c360abd927 (diff)
downloadorg.eclipse.tcf.agent-master.tar.gz
org.eclipse.tcf.agent-master.tar.xz
org.eclipse.tcf.agent-master.zip
TCF Agent: new function in HTTP server API: http_close()HEADmaster
The function requests to close HTTP connection even if the connect is "Keep Alive" type
-rw-r--r--agent/tcf/http/http-tcf.c13
-rw-r--r--agent/tcf/http/http.c55
-rw-r--r--agent/tcf/http/http.h3
-rw-r--r--agent/tcf/main/main.c2
4 files changed, 48 insertions, 25 deletions
diff --git a/agent/tcf/http/http-tcf.c b/agent/tcf/http/http-tcf.c
index 1c6c236c..65807508 100644
--- a/agent/tcf/http/http-tcf.c
+++ b/agent/tcf/http/http-tcf.c
@@ -537,12 +537,17 @@ static int get_page(const char * uri) {
}
if (strncmp(uri, "/stop/", 6) == 0) {
ClientData * cd = find_client(0, session);
+ http_printf(cd != NULL ? "OK\n" : "Already stopped\n");
+ http_close();
+ http_flush();
if (cd != NULL) {
+ if (cd->sse_out != NULL) {
+ http_resume(cd->sse_out);
+ http_printf("data: stop\n\n");
+ http_close();
+ http_flush();
+ }
close_client(cd);
- http_printf("OK\n");
- }
- else {
- http_printf("Already stopped\n");
}
return 1;
}
diff --git a/agent/tcf/http/http.c b/agent/tcf/http/http.c
index 53a280e3..c17b49c6 100644
--- a/agent/tcf/http/http.c
+++ b/agent/tcf/http/http.c
@@ -81,6 +81,7 @@ typedef struct HttpConnection {
char * page_reason;
HttpParam * page_hdrs;
int suspended;
+ int close;
int sse;
} HttpConnection;
@@ -262,27 +263,34 @@ static void http_send_done(void * x) {
async_req_post(&con->req_wr);
return;
}
- if (con->sse) {
- if (con->out.pos > 0) {
- con->send_done = 0;
- loc_free(con->send_data);
- get_byte_array_output_stream_data(&con->out, &con->send_data, &con->send_size);
- con->req_wr.u.sio.bufp = con->send_data + con->send_done;
- con->req_wr.u.sio.bufsz = con->send_size - con->send_done;
- con->write_posted = 1;
- async_req_post(&con->req_wr);
+ if (!con->close) {
+ if (con->sse) {
+ if (con->out.pos > 0) {
+ con->send_done = 0;
+ loc_free(con->send_data);
+ get_byte_array_output_stream_data(&con->out, &con->send_data, &con->send_size);
+ con->req_wr.u.sio.bufp = con->send_data + con->send_done;
+ con->req_wr.u.sio.bufsz = con->send_size - con->send_done;
+ con->write_posted = 1;
+ async_req_post(&con->req_wr);
+ }
+ return;
+ }
+ if (con->keep_alive) {
+ clear_connection_state(con);
+ con->req_rd.u.sio.bufp = con->recv_buf;
+ con->req_rd.u.sio.bufsz = con->recv_max;
+ con->read_posted = 1;
+ async_req_post(&con->req_rd);
+ return;
}
- return;
- }
- if (con->keep_alive) {
- clear_connection_state(con);
- con->req_rd.u.sio.bufp = con->recv_buf;
- con->req_rd.u.sio.bufsz = con->recv_max;
- con->read_posted = 1;
- async_req_post(&con->req_rd);
- return;
}
}
+ if (con->read_posted) {
+ shutdown(con->sock, SHUT_RDWR);
+ con->close = 1;
+ return;
+ }
close_connection(con);
}
@@ -364,6 +372,11 @@ static void http_read_done(void * x) {
con->read_posted = 0;
if (len < 0) {
+ if (con->write_posted) {
+ shutdown(con->sock, SHUT_RDWR);
+ con->close = 1;
+ return;
+ }
close_connection(con);
}
else if (len > 0) {
@@ -456,7 +469,7 @@ void http_flush(void) {
}
if (!content_type) http_printf("Content-Type: text/html\n");
if (!cache_control) http_printf("Cache-Control: no-cache\n");
- if (con->keep_alive) http_printf("Connection: keep-alive\n");
+ if (con->keep_alive && !con->close) http_printf("Connection: keep-alive\n");
if (con->sse) {
con->suspended = 1;
}
@@ -479,6 +492,10 @@ void http_flush(void) {
async_req_post(&con->req_wr);
}
+void http_close(void) {
+ current_con->close = 1;
+}
+
static int get_page(const char * uri) {
unsigned i = 0;
char * nm = tmp_strdup(uri);
diff --git a/agent/tcf/http/http.h b/agent/tcf/http/http.h
index 9c4bb638..6dd04e31 100644
--- a/agent/tcf/http/http.h
+++ b/agent/tcf/http/http.h
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2018 Xilinx, Inc. and others.
+ * Copyright (c) 2018-2019 Xilinx, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
@@ -45,6 +45,7 @@ extern void http_printf(const char * fmt, ...) ATTR_PRINTF(1, 2);
extern void http_suspend(void);
extern void http_resume(OutputStream * out);
extern void http_flush(void);
+extern void http_close(void);
typedef struct HttpListener {
int (*get_page)(const char * uri);
diff --git a/agent/tcf/main/main.c b/agent/tcf/main/main.c
index 21aca101..a82cc820 100644
--- a/agent/tcf/main/main.c
+++ b/agent/tcf/main/main.c
@@ -480,7 +480,7 @@ int main(int argc, char ** argv) {
}
loc_free(url_arr);
url_cnt = 0;
- url_cnt = 0;
+ url_max = 0;
discovery_start();
}

Back to the top