18#if ! defined(WITH_LWIP) && ! defined(WITH_CONTIKI) && ! defined (RIOT_VERSION)
28#ifdef HAVE_SYS_SELECT_H
29# include <sys/select.h>
31#ifdef HAVE_SYS_SOCKET_H
32# include <sys/socket.h>
34#ifdef HAVE_SYS_IOCTL_H
37#ifdef HAVE_NETINET_IN_H
38# include <netinet/in.h>
48#include <sys/timerfd.h>
55#include <sys/select.h>
64 struct epoll_event event;
67#if COAP_MAX_LOGGING_LEVEL < _COAP_LOG_ERR
74#if COAP_SERVER_SUPPORT
84 memset(&event, 0,
sizeof(event));
85 event.events = events;
86 event.data.ptr = sock;
88 ret = epoll_ctl(context->epfd, EPOLL_CTL_ADD, sock->
fd, &event);
101 struct epoll_event event;
104#if COAP_MAX_LOGGING_LEVEL < _COAP_LOG_ERR
111#if COAP_SERVER_SUPPORT
120 event.events = events;
121 event.data.ptr = sock;
123 ret = epoll_ctl(context->epfd, EPOLL_CTL_MOD, sock->
fd, &event);
125#if (COAP_MAX_LOGGING_LEVEL < COAP_LOG_ERR)
152 int enfds, fd_set *ereadfds, fd_set *ewritefds,
153 fd_set *eexceptfds) {
163#if ! COAP_EPOLL_SUPPORT && COAP_THREAD_SAFE
166 int enfds, fd_set *ereadfds, fd_set *ewritefds,
167 fd_set *eexceptfds) {
169 unsigned int max_sockets =
sizeof(ctx->
sockets) /
sizeof(ctx->
sockets[0]);
174#if COAP_SERVER_SUPPORT
190#if COAP_CLIENT_SUPPORT
240 int enfds, fd_set *ereadfds, fd_set *ewritefds,
241 fd_set *eexceptfds) {
244 unsigned int timeout;
245#if ! COAP_EPOLL_SUPPORT
254#if ! COAP_EPOLL_SUPPORT
300 }
else if (timeout == 0 && timeout_ms ==
COAP_IO_WAIT) {
303 if (timeout == 0 || (timeout_ms !=
COAP_IO_WAIT && timeout_ms < timeout))
304 timeout = timeout_ms;
305 tv.tv_usec = (timeout % 1000) * 1000;
306 tv.tv_sec = (long)(timeout / 1000);
315 timeout > 0 ? &tv : NULL);
324 coap_win_error_to_errno();
326 if (errno != EINTR) {
328 if (errno == EBADF) {
340 nfds = coap_io_prepare_fds(ctx, enfds, ereadfds, ewritefds, eexceptfds);
346 coap_win_error_to_errno();
348 if (errno != EINTR) {
349 if (errno == EBADF) {
413 }
else if (timeout == 0 && timeout_ms ==
COAP_IO_WAIT) {
421 if (timeout == 0 || (timeout_ms !=
COAP_IO_WAIT && timeout_ms < timeout))
422 etimeout = timeout_ms;
437 if (errno != EINTR) {
450 if (errno != EINTR) {
471#if COAP_SERVER_SUPPORT
474#if COAP_ASYNC_SUPPORT
478 coap_check_async(ctx, now, NULL);
481#if ! COAP_EPOLL_SUPPORT
499 void *main_loop_code_arg, uint32_t timeout_ms,
500 uint32_t thread_count) {
507 main_loop_code_arg, timeout_ms,
516 void *main_loop_code_arg, uint32_t timeout_ms,
517 uint32_t thread_count) {
521 if (thread_count > 1) {
529 if (main_loop_code) {
550 }
else if (timeout_ms > used_ms) {
553 unsigned int next_sec_us;
554 unsigned int next_sec_ms;
558 next_sec_ms = (next_sec_us + 999) / 1000;
559 if (next_sec_ms > timeout_ms && next_sec_ms > 1000)
567 if (thread_count == 1) {
575 if (timeout_ms > 0 && timeout_ms < used_ms) {
606#pragma GCC diagnostic ignored "-Wunused-function"
const char * coap_socket_strerror(void)
#define COAP_MAX_EPOLL_EVENTS
void coap_epoll_ctl_add(coap_socket_t *sock, uint32_t events, const char *func)
Epoll specific function to add the state of events that epoll is to track for the appropriate file de...
#define COAP_SOCKET_WANT_ACCEPT
non blocking server socket is waiting for accept
#define COAP_SOCKET_CAN_WRITE
non blocking socket can now write without blocking
#define COAP_SOCKET_WANT_READ
non blocking socket is waiting for reading
#define COAP_SOCKET_CAN_ACCEPT
non blocking server socket can now accept without blocking
#define COAP_SOCKET_WANT_WRITE
non blocking socket is waiting for writing
#define COAP_SOCKET_CAN_CONNECT
non blocking client socket can now connect without blocking
void coap_epoll_ctl_mod(coap_socket_t *sock, uint32_t events, const char *func)
Epoll specific function to modify the state of events that epoll is tracking on the appropriate file ...
#define COAP_SOCKET_WANT_CONNECT
non blocking client socket is waiting for connect
#define COAP_SOCKET_CAN_READ
non blocking socket can now read without blocking
volatile int coap_thread_quit
Library specific build wrapper for coap_internal.h.
#define SESSIONS_ITER(e, el, rtmp)
void coap_io_do_epoll_lkd(coap_context_t *ctx, struct epoll_event *events, size_t nevents)
Process all the epoll events.
int coap_io_process_loop_lkd(coap_context_t *context, coap_io_process_thread_t main_loop_code, void *main_loop_code_arg, uint32_t timeout_ms, uint32_t thread_count)
Do the coap_io_process() across thread_count threads.
void coap_io_do_io_lkd(coap_context_t *ctx, coap_tick_t now)
Processes any outstanding read, write, accept or connect I/O as indicated in the coap_socket_t struct...
int coap_io_process_lkd(coap_context_t *ctx, uint32_t timeout_ms)
The main I/O processing function.
int coap_io_process_with_fds_lkd(coap_context_t *ctx, uint32_t timeout_ms, int enfds, fd_set *ereadfds, fd_set *ewritefds, fd_set *eexceptfds)
The main message processing loop with additional fds for internal select.
unsigned int coap_io_prepare_io_lkd(coap_context_t *ctx, coap_socket_t *sockets[], unsigned int max_sockets, unsigned int *num_sockets, coap_tick_t now)
Iterates through all the coap_socket_t structures embedded in endpoints or sessions associated with t...
unsigned int coap_io_prepare_epoll_lkd(coap_context_t *ctx, coap_tick_t now)
Any now timed out delayed packet is transmitted, along with any packets associated with requested obs...
COAP_API int coap_io_process(coap_context_t *ctx, uint32_t timeout_ms)
The main I/O processing function.
int coap_io_process_configure_threads(coap_context_t *context, uint32_t thread_count)
Configure a defined number of threads to do the alternate coap_io_process() work with traffic load ba...
void coap_io_process_terminate_loop(void)
Terminate all the additional threads created by coap_io_process_loop() and break out of the main thre...
void coap_io_process_remove_threads(coap_context_t *context)
Release the coap_io_process() worker threads.
COAP_API int coap_io_process_loop(coap_context_t *context, coap_io_process_thread_t main_loop_code, void *main_loop_code_arg, uint32_t timeout_ms, uint32_t thread_count)
Do the coap_io_process() across thread_count threads.
COAP_API int coap_io_process_with_fds(coap_context_t *ctx, uint32_t timeout_ms, int enfds, fd_set *ereadfds, fd_set *ewritefds, fd_set *eexceptfds)
The main message processing loop with additional fds for internal select.
void(* coap_io_process_thread_t)(void *arg)
Main thread coap_io_process_loop activity.
void coap_expire_cache_entries(coap_context_t *context)
Expire coap_cache_entry_t entries.
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
#define COAP_TICKS_PER_SECOND
Use ms resolution on POSIX systems.
uint64_t coap_ticks_to_rt_us(coap_tick_t t)
Helper function that converts coap ticks to POSIX wallclock time in us.
void coap_send_recv_terminate(void)
Terminate any active coap_send_recv() sessions.
void coap_ticks(coap_tick_t *t)
Returns the current value of an internal tick counter.
#define coap_lock_unlock()
Dummy for no thread-safe code.
#define coap_lock_check_locked()
Dummy for no thread-safe code.
#define coap_lock_callback_release(func, failed)
Dummy for no thread-safe code.
#define coap_lock_lock(failed)
Dummy for no thread-safe code.
#define coap_log_debug(...)
#define coap_log_err(...)
The CoAP stack's global state is stored in a coap_context_t object.
coap_socket_t * sockets[64]
Track different socket information in coap_io_process_with_fds_lkd()
unsigned int num_sockets
Number of sockets being tracked.
coap_session_t * sessions
client sessions
fd_set exceptfds
Used for select call in coap_io_process_with_fds_lkd()
coap_endpoint_t * endpoint
the endpoints used for listening
coap_tick_t next_timeout
When the next timeout is to occur.
Abstraction of virtual endpoint that can be attached to coap_context_t.
coap_context_t * context
endpoint's context
coap_session_t * sessions
hash table or list of active sessions
coap_socket_t sock
socket object for the interface, if any
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_socket_t sock
socket object for the session, if any
coap_context_t * context
session's context
coap_session_t * session
Used to determine session owner.
coap_endpoint_t * endpoint
Used by the epoll logic for a listening endpoint.
coap_socket_flags_t flags
1 or more of COAP_SOCKET* flag values