From 45006ae0313c3d0e569d3aae9e040c24deba338b Mon Sep 17 00:00:00 2001 From: Mario Kicherer Date: Tue, 11 Mar 2025 17:58:52 +0100 Subject: [PATCH] coap_io: do not call select() for contexts without sockets on Windows --- src/coap_io.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/coap_io.c b/src/coap_io.c index 47207ca8..1e158dce 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -1848,13 +1848,18 @@ coap_io_process_with_fds_lkd(coap_context_t *ctx, uint32_t timeout_ms, tv.tv_sec = (long)(timeout / 1000); } - /* Unlock so that other threads can lock/update ctx */ - coap_lock_unlock(ctx); + /* on Windows select will return an error if called without FDs */ + if (nfds > 0) { + /* Unlock so that other threads can lock/update ctx */ + coap_lock_unlock(ctx); - result = select((int)nfds, &ctx->readfds, &ctx->writefds, &ctx->exceptfds, - timeout > 0 ? &tv : NULL); + result = select((int)nfds, &ctx->readfds, &ctx->writefds, &ctx->exceptfds, + timeout > 0 ? &tv : NULL); - coap_lock_lock(ctx, return -1); + coap_lock_lock(ctx, return -1); + } else { + result = 0; + } if (result < 0) { /* error */ #ifdef _WIN32