From: <ge...@op...> - 2025-08-14 08:07:15
|
This is an automated email from Gerrit. "Marek Vrbka <mar...@co...>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9081 -- gerrit commit cf72ef7496164318fabc612d107b71395f4706e9 Author: Marek Vrbka <mar...@co...> Date: Wed Aug 13 15:36:21 2025 +0200 replacements: return 0 on Windows if no sockets are provided On Windows 11, if select is called with empty sets, it fails and returns WSAINVAL, on POSIX this works fine. This patch addresses it by detecting this case in OpenOCD replacements and returning 0 in these cases. This fixes Windows crash if no services are enabled. Change-Id: I601878671caf4ae44e105d6a819251d2d96c607c Signed-off-by: Marek Vrbka <mar...@co...> diff --git a/src/helper/replacements.c b/src/helper/replacements.c index 782d975184..c082ae228a 100644 --- a/src/helper/replacements.c +++ b/src/helper/replacements.c @@ -19,6 +19,7 @@ #define IN_REPLACEMENTS_C #include "replacements.h" +#include <stdbool.h> #include <stdlib.h> #include <string.h> @@ -152,9 +153,26 @@ int win_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct time FD_ZERO(&sock_write); FD_ZERO(&sock_except); + /* On Windows, if all provided sets are empty/NULL an error code of -1 is returned + * and WSAGetLastError() returns WSAEINVAL instead of delaying. + * We check for this case, delay and return 0 instead of calling select(). */ + if (rfds && rfds->fd_count == 0) + rfds = NULL; + if (wfds && wfds->fd_count == 0) + wfds = NULL; + if (efds && efds->fd_count == 0) + efds = NULL; + if (!rfds && !wfds && !efds && tv) { + sleep(tv->tv_sec); + usleep(tv->tv_usec); + return 0; + } + + /* build an array of handles for non-sockets */ for (i = 0; i < max_fd; i++) { if (SAFE_FD_ISSET(i, rfds) || SAFE_FD_ISSET(i, wfds) || SAFE_FD_ISSET(i, efds)) { + any_fd_set = true; intptr_t handle = (intptr_t) _get_osfhandle(i); handles[n_handles] = (HANDLE)handle; if (handles[n_handles] == INVALID_HANDLE_VALUE) { -- |