libcoap 4.3.5-develop-19cef11
Application I/O Handling

API for Application Input / Output checking. More...

+ Collaboration diagram for Application I/O Handling:

Macros

#define COAP_IO_WAIT   0
 
#define COAP_IO_NO_WAIT   ((uint32_t)-1)
 

Functions

COAP_API int coap_io_process (coap_context_t *ctx, uint32_t timeout_ms)
 The main I/O processing function. More...
 
COAP_API int coap_io_process_with_fds (coap_context_t *ctx, uint32_t timeout_ms, int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds)
 The main message processing loop with additional fds for internal select. More...
 
COAP_API int coap_io_pending (coap_context_t *context)
 Check to see if there is any i/o pending for the context. More...
 
COAP_API unsigned int coap_io_prepare_io (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 the ctx to determine which are wanting any read, write, accept or connect I/O (COAP_SOCKET_WANT_xxx is set). More...
 
COAP_API void coap_io_do_io (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 structures (COAP_SOCKET_CAN_xxx set) embedded in endpoints or sessions associated with ctx. More...
 
COAP_API unsigned int coap_io_prepare_epoll (coap_context_t *ctx, coap_tick_t now)
 Any now timed out delayed packet is transmitted, along with any packets associated with requested observable response. More...
 
COAP_API void coap_io_do_epoll (coap_context_t *ctx, struct epoll_event *events, size_t nevents)
 Process all the epoll events. More...
 

Detailed Description

API for Application Input / Output checking.

Macro Definition Documentation

◆ COAP_IO_NO_WAIT

#define COAP_IO_NO_WAIT   ((uint32_t)-1)

Definition at line 663 of file coap_net.h.

◆ COAP_IO_WAIT

#define COAP_IO_WAIT   0

Definition at line 662 of file coap_net.h.

Function Documentation

◆ coap_io_do_epoll()

COAP_API void coap_io_do_epoll ( coap_context_t ctx,
struct epoll_event *  events,
size_t  nevents 
)

Process all the epoll events.

Note: If epoll support is compiled into libcoap, coap_io_do_epoll() must be used instead of coap_io_do_io().

Internal function

Parameters
ctxThe current CoAP context.
eventsThe list of events returned from an epoll_wait() call.
neventsThe number of events.

Definition at line 2512 of file coap_net.c.

+ Here is the call graph for this function:

◆ coap_io_do_io()

COAP_API void coap_io_do_io ( 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 structures (COAP_SOCKET_CAN_xxx set) embedded in endpoints or sessions associated with ctx.

Note: If epoll support is compiled into libcoap, coap_io_do_epoll() must be used instead of coap_io_do_io().

Internal function.

Parameters
ctxThe CoAP context
nowCurrent time

Definition at line 2451 of file coap_net.c.

+ Here is the call graph for this function:

◆ coap_io_pending()

COAP_API int coap_io_pending ( coap_context_t context)

Check to see if there is any i/o pending for the context.

This includes Observe active (client) and partial large block transfers.

coap_io_process() is called internally to try to send outstanding data as well as process any packets just received.

Parameters
contextThe CoAP context.
Returns
1 I/O still pending, 0 no I/O pending.

Definition at line 1825 of file coap_io.c.

+ Here is the call graph for this function:

◆ coap_io_prepare_epoll()

COAP_API unsigned int coap_io_prepare_epoll ( coap_context_t ctx,
coap_tick_t  now 
)

Any now timed out delayed packet is transmitted, along with any packets associated with requested observable response.

In addition, it returns when the next expected I/O is expected to take place (e.g. a packet retransmit).

Note: If epoll support is compiled into libcoap, coap_io_prepare_epoll() must be used instead of coap_io_prepare_io().

Internal function.

Parameters
ctxThe CoAP context
nowCurrent time.
Returns
timeout Maxmimum number of milliseconds that can be used by a epoll_wait() to wait for network events or 0 if wait should be forever.

Definition at line 1242 of file coap_io.c.

+ Here is the call graph for this function:

◆ coap_io_prepare_io()

COAP_API unsigned int coap_io_prepare_io ( 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 the ctx to determine which are wanting any read, write, accept or connect I/O (COAP_SOCKET_WANT_xxx is set).

If set, the coap_socket_t is added to the sockets.

Any now timed out delayed packet is transmitted, along with any packets associated with requested observable response.

In addition, it returns when the next expected I/O is expected to take place (e.g. a packet retransmit).

Prior to calling coap_io_do_io(), the sockets must be tested to see if any of the COAP_SOCKET_WANT_xxx have the appropriate information and if so, COAP_SOCKET_CAN_xxx is set. This typically will be done after using a select() call.

Note: If epoll support is compiled into libcoap, coap_io_prepare_epoll() must be used instead of coap_io_prepare_io().

Internal function.

Parameters
ctxThe CoAP context
socketsArray of socket descriptors, filled on output
max_socketsSize of socket array.
num_socketsPointer to the number of valid entries in the socket arrays on output.
nowCurrent time.
Returns
timeout Maxmimum number of milliseconds that can be used by a select() to wait for network events or 0 if wait should be forever.

Definition at line 1303 of file coap_io.c.

+ Here is the call graph for this function:

◆ coap_io_process()

COAP_API int coap_io_process ( coap_context_t ctx,
uint32_t  timeout_ms 
)

The main I/O processing function.

All pending network I/O is completed, and then optionally waits for the next input packet.

This internally calls coap_io_prepare_io(), then select() for the appropriate sockets, updates COAP_SOCKET_CAN_xxx where appropriate and then calls coap_io_do_io() before returning with the time spent in the function.

Alternatively, if libcoap is compiled with epoll support, this internally calls coap_io_prepare_epoll(), then epoll_wait() for waiting for any file descriptors that have (internally) been set up with epoll_ctl() and finally coap_io_do_epoll() before returning with the time spent in the function.

Parameters
ctxThe CoAP context
timeout_msMinimum number of milliseconds to wait for new packets before returning after doing any processing. If COAP_IO_WAIT, the call will block until the next internal action (e.g. packet retransmit) if any, or block until the next packet is received whichever is the sooner and do the necessary processing. If COAP_IO_NO_WAIT, the function will return immediately after processing without waiting for any new input packets to arrive.
Returns
Number of milliseconds spent in function or -1 if there was an error

Definition at line 1581 of file coap_io.c.

+ Here is the call graph for this function:

◆ coap_io_process_with_fds()

COAP_API int coap_io_process_with_fds ( coap_context_t ctx,
uint32_t  timeout_ms,
int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds 
)

The main message processing loop with additional fds for internal select.

Parameters
ctxThe CoAP context
timeout_msMinimum number of milliseconds to wait for new packets before returning after doing any processing. If COAP_IO_WAIT, the call will block until the next internal action (e.g. packet retransmit) if any, or block until the next packet is received whichever is the sooner and do the necessary processing. If COAP_IO_NO_WAIT, the function will return immediately after processing without waiting for any new input packets to arrive.
nfdsThe maximum FD set in readfds, writefds or exceptfds plus one,
readfdsRead FDs to additionally check for in internal select() or NULL if not required.
writefdsWrite FDs to additionally check for in internal select() or NULL if not required.
exceptfdsExcept FDs to additionally check for in internal select() or NULL if not required.
Returns
Number of milliseconds spent in coap_io_process_with_fds, or -1 if there was an error. If defined, readfds, writefds, exceptfds are updated as returned by the internal select() call.

Definition at line 1596 of file coap_io.c.

+ Here is the call graph for this function: