server: permit the add_service function to return the created service 17/5717/4
authorTarek BOCHKATI <tarek.bouchkati@gmail.com>
Mon, 8 Jun 2020 23:15:49 +0000 (00:15 +0100)
committerAntonio Borneo <borneo.antonio@gmail.com>
Sat, 7 Nov 2020 20:49:53 +0000 (20:49 +0000)
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
src/server/gdb_server.c
src/server/server.c
src/server/server.h
src/server/tcl_server.c
src/server/telnet_server.c
src/target/openrisc/jsp_server.c

index c96be1034ee9b48c256a1405f4300981c39d07e4..bb4c1317de90ff5a4f0296640bfb188deff0bc42 100644 (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;
index e53f37d0b8ee05c341730be64ce6becf84eeed76..114af763244067561875201ef69f93a231ac0b71 100644 (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;
 }
 
index ff2ada9cbe68ff53c3d36e291275152667c47f24..99f5fe2eddd2e9c1ee99df32d1ff3830755df944 100644 (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);
index 1ecb827a1ab007325d9ec5fa4c41c5b6f20eadbc..07213ae79978ea6041cc2e78f626ab2675b13aca 100644 (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)
index 407ab68aefcd74d41d31f205e6e16fb3828cbef2..4f88d3a542bb6ca83423aed8e4144bee667c06c2 100644 (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);
index 4dbe63527da639d6aa1819e8df13cfbc7883fcdb..b4b25665dae598269323ea3f26e88b553e6e1c63 100644 (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)

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)