diff options
author | Tarek BOCHKATI <tarek.bouchkati@gmail.com> | 2020-06-09 00:15:49 +0100 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2020-11-07 20:49:53 +0000 |
commit | 7e6556b3cad8c82d4670a68cd49756dabb8c4729 (patch) | |
tree | ea24d284b1f01ff081a1e81804a32775854d188b /src/server | |
parent | 72a1010c9f60c75faa051cf2033c62b11fa42fcf (diff) | |
download | riscv-openocd-7e6556b3cad8c82d4670a68cd49756dabb8c4729.zip riscv-openocd-7e6556b3cad8c82d4670a68cd49756dabb8c4729.tar.gz riscv-openocd-7e6556b3cad8c82d4670a68cd49756dabb8c4729.tar.bz2 |
server: permit the add_service function to return the created service
returning the created service seems useful:
as the only method to get the freshly created service is by getting the
last item in the services linked list, and this seems to be like an
intrusion to service internal mechanism.
possibly, we could get the service from a connection but this is possible
only from [new_connection|input|connection_closed]_handler_t, but this is
not always practical:
example: armv7m: add a TCP channel to stream captured trace
http://openocd.zylin.com/#/c/5345/
here we poll for trace and broadcast to all connections
outside of these xxx_handler_t functions
also, storing one of the connections in new_connection_handler_t and get
the service from it is possible, but this will make the code less readable.
Change-Id: I5fef1baecec1e054953c6faf5b99d864ecc97f02
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/5717
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/gdb_server.c | 2 | ||||
-rw-r--r-- | src/server/server.c | 7 | ||||
-rw-r--r-- | src/server/server.h | 2 | ||||
-rw-r--r-- | src/server/tcl_server.c | 2 | ||||
-rw-r--r-- | src/server/telnet_server.c | 2 |
5 files changed, 10 insertions, 5 deletions
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index c96be10..bb4c131 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -3509,7 +3509,7 @@ static int gdb_target_start(struct target *target, const char *port) ret = add_service("gdb", port, target->gdb_max_connections, &gdb_new_connection, &gdb_input, - &gdb_connection_closed, gdb_service); + &gdb_connection_closed, gdb_service, NULL); /* initialize all targets gdb service with the same pointer */ { struct target_list *head; diff --git a/src/server/server.c b/src/server/server.c index e53f37d..114af76 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -210,7 +210,8 @@ int add_service(char *name, new_connection_handler_t new_connection_handler, input_handler_t input_handler, connection_closed_handler_t connection_closed_handler, - void *priv) + void *priv, + struct service **new_service) { struct service *c, **p; struct hostent *hp; @@ -346,6 +347,10 @@ int add_service(char *name, ; *p = c; + /* if new_service is not NULL, return the created service into it */ + if (new_service) + *new_service = c; + return ERROR_OK; } diff --git a/src/server/server.h b/src/server/server.h index ff2ada9..99f5fe2 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -77,7 +77,7 @@ struct service { int add_service(char *name, const char *port, int max_connections, new_connection_handler_t new_connection_handler, input_handler_t in_handler, connection_closed_handler_t close_handler, - void *priv); + void *priv, struct service **new_service); int remove_service(const char *name, const char *port); int server_host_os_entry(void); diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index 1ecb827..07213ae 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -285,7 +285,7 @@ int tcl_init(void) return add_service("tcl", tcl_port, CONNECTION_LIMIT_UNLIMITED, &tcl_new_connection, &tcl_input, - &tcl_closed, NULL); + &tcl_closed, NULL, NULL); } COMMAND_HANDLER(handle_tcl_port_command) diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index 407ab68..4f88d3a 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -694,7 +694,7 @@ int telnet_init(char *banner) int ret = add_service("telnet", telnet_port, CONNECTION_LIMIT_UNLIMITED, telnet_new_connection, telnet_input, telnet_connection_closed, - telnet_service); + telnet_service, NULL); if (ret != ERROR_OK) { free(telnet_service); |