Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdeep1 committed Dec 18, 2024
1 parent 71edfe0 commit 8e16c24
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cmake_coap_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
/* Define to 1 if you have the <sys/unistd.h> header file. */
#cmakedefine HAVE_SYS_UNISTD_H @HAVE_SYS_UNISTD_H@

/* Define to 1 if you have the <fcntl.h> header file. */
#cmakedefine HAVE_FCNTL_H @HAVE_FCNTL_H@

/* Define to 1 if you have the <time.h> header file. */
#cmakedefine HAVE_TIME_H @HAVE_TIME_H@

Expand Down
3 changes: 3 additions & 0 deletions coap_config.h.riot
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@
/* Define to 1 if you have the <sys/unistd.h> header file. */
#define HAVE_SYS_UNISTD_H 1

/* Define to 1 if you have the <fcntl.h> header file. */
#define HAVE_FCNTL_H 1

/* Define to 1 if you have the <time.h> header file. */
#define HAVE_TIME_H 1

Expand Down
1 change: 1 addition & 0 deletions libcoap-3.map
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions libcoap-3.sym
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/coap_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 */;
}
Expand Down
23 changes: 16 additions & 7 deletions src/coap_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8e16c24

Please sign in to comment.