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
This commit is contained in:
Tarek BOCHKATI 2020-06-09 00:15:49 +01:00 committed by Antonio Borneo
parent 72a1010c9f
commit 7e6556b3ca
6 changed files with 12 additions and 6 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -207,7 +207,8 @@ int jsp_init(struct or1k_jtag *jtag_info, char *banner)
jsp_new_connection,
jsp_input,
jsp_connection_closed,
jsp_service);
jsp_service,
NULL);
}
COMMAND_HANDLER(handle_jsp_port_command)