diff options
author | Tarek BOCHKATI <tarek.bouchkati@gmail.com> | 2020-04-23 11:00:31 +0100 |
---|---|---|
committer | Antonio Borneo <borneo.antonio@gmail.com> | 2020-06-14 14:23:48 +0100 |
commit | 9a690c6bdb18d722a99d5752ac9c3ae1733cf22e (patch) | |
tree | cad6d8490670f0b4e2deb340cf8a46255b5b2629 /src | |
parent | 7e78c04f1c275176bdee8f9d2553300218164577 (diff) | |
download | riscv-openocd-9a690c6bdb18d722a99d5752ac9c3ae1733cf22e.zip riscv-openocd-9a690c6bdb18d722a99d5752ac9c3ae1733cf22e.tar.gz riscv-openocd-9a690c6bdb18d722a99d5752ac9c3ae1733cf22e.tar.bz2 |
openocd: fix issue in WIN32 with TCP adapters
Issue: server_quit is called before adapter_quit:
In WIN32 only in server_quit we do an WSACleanup,
which terminates/closes all active sockets.
So if the adapter is TCP based, the adapter.quit handler
will fail if it will need to send some commands through TCP.
Example: close_socket in jtag_vpi_quit will fail in WIN32
because the socket is already closed
and the errno is set as "Bad File Descriptor"
To fix that we introduced new functions called server_host_os_entry/quit
to manage specific OS setup (hence WSA for sockets in WINDOWS) in order
to delay WSACleanup after adapter_quit().
Change-Id: Ie4afacafe123857f6ae300e376bdfcf0d8c027ac
Signed-off-by: Tarek BOCHKATI <tarek.bouchkati@gmail.com>
Reviewed-on: http://openocd.zylin.com/5456
Tested-by: jenkins
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/openocd.c | 4 | ||||
-rw-r--r-- | src/server/server.c | 17 | ||||
-rw-r--r-- | src/server/server.h | 3 |
3 files changed, 22 insertions, 2 deletions
diff --git a/src/openocd.c b/src/openocd.c index 2a9a0b3..8862284 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -345,6 +345,8 @@ int openocd_main(int argc, char *argv[]) command_context_mode(cmd_ctx, COMMAND_CONFIG); command_set_output_handler(cmd_ctx, configuration_output_handler, NULL); + server_host_os_entry(); + /* Start the executable meat that can evolve into thread in future. */ ret = openocd_thread(argc, argv, cmd_ctx); @@ -360,6 +362,8 @@ int openocd_main(int argc, char *argv[]) adapter_quit(); + server_host_os_close(); + /* Shutdown commandline interface */ command_exit(cmd_ctx); diff --git a/src/server/server.c b/src/server/server.c index 07b7ae4..23a15ef 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -631,7 +631,7 @@ static void sigkey_handler(int sig) #endif -int server_preinit(void) +int server_host_os_entry(void) { /* this currently only calls WSAStartup on native win32 systems * before any socket operations are performed. @@ -647,7 +647,21 @@ int server_preinit(void) LOG_ERROR("Failed to Open Winsock"); return ERROR_FAIL; } +#endif + return ERROR_OK; +} +int server_host_os_close(void) +{ +#ifdef _WIN32 + WSACleanup(); +#endif + return ERROR_OK; +} + +int server_preinit(void) +{ +#ifdef _WIN32 /* register ctrl-c handler */ SetConsoleCtrlHandler(ControlHandler, TRUE); @@ -688,7 +702,6 @@ int server_quit(void) target_quit(); #ifdef _WIN32 - WSACleanup(); SetConsoleCtrlHandler(ControlHandler, FALSE); return ERROR_OK; diff --git a/src/server/server.h b/src/server/server.h index ab9b72f..f4cc39d 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -80,6 +80,9 @@ int add_service(char *name, const char *port, void *priv); int remove_service(const char *name, const char *port); +int server_host_os_entry(void); +int server_host_os_close(void); + int server_preinit(void); int server_init(struct command_context *cmd_ctx); int server_quit(void); |