libcoap 4.3.5-develop-72190a8
Loading...
Searching...
No Matches
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.
 
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.
 
COAP_API int coap_io_pending (coap_context_t *context)
 Check to see if there is any i/o pending for the context.
 
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).
 
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.
 
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.
 
COAP_API void coap_io_do_epoll (coap_context_t *ctx, struct epoll_event *events, size_t nevents)
 Process all the epoll events.
 
COAP_API coap_fd_t coap_socket_get_fd (coap_socket_t *socket)
 Get the libcoap internal file descriptor for a socket.
 
COAP_API unsigned int coap_io_get_fds (coap_context_t *context, coap_fd_t read_fds[], unsigned int *have_read_fds, unsigned int max_read_fds, coap_fd_t write_fds[], unsigned int *have_write_fds, unsigned int max_write_fds, unsigned int *rem_timeout_ms)
 
COAP_API coap_socket_flags_t coap_socket_get_flags (coap_socket_t *socket)
 Get the libcoap internal flags for a socket.
 
COAP_API void coap_socket_set_flags (coap_socket_t *socket, coap_socket_flags_t flags)
 Set the libcoap internal flags for a socket.
 

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 2517 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 2456 of file coap_net.c.

+ Here is the call graph for this function:

◆ coap_io_get_fds()

COAP_API unsigned int coap_io_get_fds ( coap_context_t context,
coap_fd_t  read_fds[],
unsigned int *  have_read_fds,
unsigned int  max_read_fds,
coap_fd_t  write_fds[],
unsigned int *  have_write_fds,
unsigned int  max_write_fds,
unsigned int *  rem_timeout_ms 
)

Definition at line 1588 of file coap_io.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 1976 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 1246 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 1307 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 1726 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 1741 of file coap_io.c.

+ Here is the call graph for this function:

◆ coap_socket_get_fd()

COAP_API coap_fd_t coap_socket_get_fd ( coap_socket_t socket)

Get the libcoap internal file descriptor for a socket.

This can be used to integrate libcoap in an external event loop instead of using one of its builtin event loops.

Parameters
socketThe CoAP socket
Returns
The libcoap file descriptor or COAP_INVALID_SOCKET if the platform is not using file descriptors.

Definition at line 2046 of file coap_io.c.

◆ coap_socket_get_flags()

COAP_API coap_socket_flags_t coap_socket_get_flags ( coap_socket_t socket)

Get the libcoap internal flags for a socket.

This can be used to integrate libcoap in an external event loop instead of using one of its builtin event loops.

Parameters
socketThe CoAP socket
Returns
the OR-ed COAP_SOCKET* flags for this socket

Definition at line 2056 of file coap_io.c.

◆ coap_socket_set_flags()

COAP_API void coap_socket_set_flags ( coap_socket_t socket,
coap_socket_flags_t  flags 
)

Set the libcoap internal flags for a socket.

This can be used to integrate libcoap in an external event loop instead of using one of its builtin event loops.

Parameters
socketThe CoAP socket
flagsThe new flags for this socket

Definition at line 2061 of file coap_io.c.