From 8e16c24c7c0fb2d637438b3ab70dcb751652da64 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Wed, 18 Dec 2024 13:09:13 +0000 Subject: [PATCH] Update --- CMakeLists.txt | 1 + cmake_coap_config.h.in | 3 +++ coap_config.h.riot | 3 +++ libcoap-3.map | 1 + libcoap-3.sym | 1 + src/coap_io.c | 12 ++++++++++-- src/coap_net.c | 23 ++++++++++++++++------- 7 files changed, 35 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c9e3434bc..acab5bad31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -284,6 +284,7 @@ check_include_file(sys/stat.h HAVE_SYS_STAT_H) check_include_file(sys/time.h HAVE_SYS_TIME_H) check_include_file(sys/types.h HAVE_SYS_TYPES_H) check_include_file(sys/unistd.h HAVE_SYS_UNISTD_H) +check_include_file(fcntl.h HAVE_FCNTL_H) check_include_file(time.h HAVE_TIME_H) check_include_file(unistd.h HAVE_UNISTD_H) check_include_file(float.h HAVE_FLOAT_H) diff --git a/cmake_coap_config.h.in b/cmake_coap_config.h.in index 3fff04e220..9f1c22819f 100644 --- a/cmake_coap_config.h.in +++ b/cmake_coap_config.h.in @@ -142,6 +142,9 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_SYS_UNISTD_H @HAVE_SYS_UNISTD_H@ +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_FCNTL_H @HAVE_FCNTL_H@ + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_TIME_H @HAVE_TIME_H@ diff --git a/coap_config.h.riot b/coap_config.h.riot index fec3d8b998..d5b72e27cb 100644 --- a/coap_config.h.riot +++ b/coap_config.h.riot @@ -349,6 +349,9 @@ /* Define to 1 if you have the header file. */ #define HAVE_SYS_UNISTD_H 1 +/* Define to 1 if you have the header file. */ +#define HAVE_FCNTL_H 1 + /* Define to 1 if you have the header file. */ #define HAVE_TIME_H 1 diff --git a/libcoap-3.map b/libcoap-3.map index 85c35e53ed..3745a83088 100644 --- a/libcoap-3.map +++ b/libcoap-3.map @@ -223,6 +223,7 @@ global: coap_resolve_address_info; coap_resource_get_uri_path; coap_resource_get_userdata; + coap_resource_has_observers; coap_resource_init; coap_resource_notify_observers; coap_resource_proxy_uri_init2; diff --git a/libcoap-3.sym b/libcoap-3.sym index 79680b9d27..a2e73f41a6 100644 --- a/libcoap-3.sym +++ b/libcoap-3.sym @@ -221,6 +221,7 @@ coap_resize_binary coap_resolve_address_info coap_resource_get_uri_path coap_resource_get_userdata +coap_resource_has_observers coap_resource_init coap_resource_notify_observers coap_resource_proxy_uri_init diff --git a/src/coap_io.c b/src/coap_io.c index f5cfdca85f..2a91ce325e 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -543,7 +543,12 @@ coap_update_io_timer(coap_context_t *context, coap_tick_t delay) { /* No delay, or context->next_timeout needs reducing */ char byte = 0; - write(context->pipefd[1], &byte, 1); +#ifdef _WIN32 +#define write(a,b,c) _write(a,b,c) +#endif + if (write(context->pipefd[1], &byte, 1) == -1) { + /* Ignore error - need to test write(function) */ + } } } if (context->next_timeout == 0 || context->next_timeout > now + delay) { @@ -1894,12 +1899,15 @@ coap_io_process_with_fds_lkd(coap_context_t *ctx, uint32_t timeout_ms, select((int)nfds, &ctx->readfds, &ctx->writefds, &ctx->exceptfds, &tv); #endif /* COAP_THREAD_SAFE */ if (ctx->pipefd[0] != -1) { - /* Timeout has been reduced */ if (FD_ISSET(ctx->pipefd[0], &ctx->readfds)) { + /* Timeout has been reduced */ char byte; /* Check the result from read() to suppress the warning on * systems that declare read() with warn_unused_result. */ +#ifdef _WIN32 +#define read(a,b,c) _read(a,b,c) +#endif if (read(ctx->pipefd[0], &byte, sizeof(byte)) == -1) { /* do nothing */; } diff --git a/src/coap_net.c b/src/coap_net.c index 3560e0f4bd..223d846429 100644 --- a/src/coap_net.c +++ b/src/coap_net.c @@ -698,20 +698,27 @@ coap_new_context(const coap_address_t *listen_addr) { } } #else /* COAP_EPOLL_SUPPORT */ +#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) int flags; +#ifdef _WIN32 +#define pipe(a) _pipe(a, 128, _O_BINARY) +#endif if (pipe(c->pipefd) == -1) { coap_log_err("coap_new_context: Unable to pipe(): %s (%d)\n", coap_socket_strerror(), errno); - goto onerror; + } else { +#infdef _WIN32 + flags = fcntl(c->pipefd[0], F_GETFL); + flags |= O_NONBLOCK; + fcntl(c->pipefd[0], F_SETFL, flags); + flags = fcntl(c->pipefd[1], F_GETFL); + flags |= O_NONBLOCK; + fcntl(c->pipefd[1], F_SETFL, flags); +#endif } - flags = fcntl(c->pipefd[0], F_GETFL); - flags |= O_NONBLOCK; - fcntl(c->pipefd[0], F_SETFL, flags); - flags = fcntl(c->pipefd[1], F_GETFL); - flags |= O_NONBLOCK; - fcntl(c->pipefd[1], F_SETFL, flags); +#endif /* ! WITH_LWIP && ! WITH_CONTIKI */ #endif /* COAP_EPOLL_SUPPORT */ if (coap_dtls_is_supported() || coap_tls_is_supported()) { @@ -847,12 +854,14 @@ coap_free_context_lkd(coap_context_t *context) { context->epfd = -1; } #else /* COAP_EPOLL_SUPPORT */ +#if !defined(WITH_LWIP) && !defined(WITH_CONTIKI) if (context->pipefd[0] != -1) { close(context->pipefd[0]); close(context->pipefd[0]); context->pipefd[0] = -1; context->pipefd[1] = -1; } +#endif /* ! WITH_LWIP && ! WITH_CONTIKI */ #endif /* COAP_EPOLL_SUPPORT */ #if COAP_SERVER_SUPPORT