mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-04 00:45:40 +03:00
coap_io.c: Add in support for getting state of internal file descriptors
Add in a new function coap_io_get_fds() to get the lists of (internal to libcoap) file descriptors that are in a read or write pending state, as well as the timeout time for the next internal to libcoap activity (e.g. packet retransmission).
This commit is contained in:
1 parent
32c124f7d5
commit
a87fb0c1cf
8 files changed
+238
-6
No files matched your search
@@ -845,6 +845,28 @@ COAP_API void coap_io_do_epoll(coap_context_t *ctx, struct epoll_event *events,
|
||||
*/
|
||||
COAP_API coap_fd_t coap_socket_get_fd(coap_socket_t *socket);
|
||||
|
||||
/*
|
||||
* Get the current libcoap usage of file descriptors that are in a read or write pending state.
|
||||
*
|
||||
* @param context The current CoAP context.
|
||||
* @param read_fds Array to populate with file descriptors in the read pending state.
|
||||
* @param have_read_fds Updated wth the number of fds found in read pending state.
|
||||
* @param max_read_fds Maximum size of read_fds[] array.
|
||||
* @param write_fds Array to populate with file descriptors in the write pending state.
|
||||
* @param have_write_fds Updated wth the number of fds found in write pending state.
|
||||
* @param max_write_fds Maximum size of write_fds[] array.
|
||||
* @param rem_timeout_ms Remaining timeout time to next libcoap activity in milli-secs.
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0 if error.
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -173,10 +173,10 @@ struct coap_context_t {
|
||||
#endif /* COAP_SERVER_SUPPORT */
|
||||
void *app; /**< application-specific data */
|
||||
uint32_t max_token_size; /**< Largest token size supported RFC8974 */
|
||||
coap_tick_t next_timeout; /**< When the next timeout is to occur */
|
||||
#ifdef COAP_EPOLL_SUPPORT
|
||||
int epfd; /**< External FD for epoll */
|
||||
int eptimerfd; /**< Internal FD for timeout */
|
||||
coap_tick_t next_timeout; /**< When the next timeout is to occur */
|
||||
#else /* ! COAP_EPOLL_SUPPORT */
|
||||
#if !defined(RIOT_VERSION) && !defined(WITH_CONTIKI)
|
||||
fd_set readfds, writefds, exceptfds; /**< Used for select call
|
||||
@@ -779,6 +779,30 @@ int coap_io_process_with_fds_lkd(coap_context_t *ctx, uint32_t timeout_ms,
|
||||
fd_set *exceptfds);
|
||||
#endif /* ! RIOT_VERSION && ! WITH_CONTIKI */
|
||||
|
||||
/*
|
||||
* Get the current libcoap usage of file descriptors that are in a read or write pending state.
|
||||
*
|
||||
* Note: This function must be called in the locked state.
|
||||
*
|
||||
* @param context The current CoAP context.
|
||||
* @param read_fds Array to populate with file descriptors in the read pending state.
|
||||
* @param have_read_fds Updated wth the number of fds found in read pending state.
|
||||
* @param max_read_fds Maximum size of read_fds[] array.
|
||||
* @param write_fds Array to populate with file descriptors in the write pending state.
|
||||
* @param have_write_fds Updated wth the number of fds found in write pending state.
|
||||
* @param max_write_fds Maximum size of write_fds[] array.
|
||||
* @param rem_timeout_ms Remaining timeout time to next libcoap activity in milli-secs.
|
||||
*
|
||||
* @return @c 1 if successful, else @c 0 if error.
|
||||
*/
|
||||
unsigned int coap_io_get_fds_lkd(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);
|
||||
|
||||
/**
|
||||
* Sends a CoAP message to given peer. The memory that is
|
||||
* allocated for the pdu will be released by coap_send_lkd().
|
||||
|
||||
Reference in new issue
Block a user