Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coap_io.c: Add in support for getting state of internal file descriptors #1556

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

mrdeep1
Copy link
Collaborator

@mrdeep1 mrdeep1 commented Dec 14, 2024

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.

@mkicherer
Copy link

It looks like this only works if coap_io_process_with_fds_lkd is called before as this will set ctx->num_sockets. In my case (libcoapy under Windows), ctx->num_sockets is always zero and coap_io_get_fds will not return any fds.

This seems to work for me:

  coap_endpoint_t *ep;
  LL_FOREACH(ctx->endpoint, ep) {
    if (ep->sock.flags & (COAP_SOCKET_WANT_READ|COAP_SOCKET_WANT_ACCEPT)) {
      if (!coap_add_fd(ep->sock.fd, read_fds, have_read_fds, max_read_fds))
        return 0;
    }
    if (ep->sock.flags & (COAP_SOCKET_WANT_WRITE|COAP_SOCKET_WANT_CONNECT)) {
      if (!coap_add_fd(ep->sock.fd, write_fds, have_write_fds, max_write_fds))
        return 0;
    }
  }

I am currently stuck with an other issue, so I cannot test it completely but it looks good so far.

@mkicherer
Copy link

Ah, I see you also made this change. I will pull the new commit.

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).
@mkicherer
Copy link

I got my bug fixed and it works flawlessly with this commit. Thank you!

@mrdeep1 mrdeep1 merged commit a87fb0c into obgm:develop Dec 18, 2024
31 checks passed
@mrdeep1 mrdeep1 deleted the get_context_fds branch December 18, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants