coap_io: do not call select() for contexts without sockets on Windows #1599
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
in a NodeJS environment, my wrapper library for libcoap maintains the list of created contexts and provides a loop() function that will call
coap_io_process
with every context andCOAP_IO_NO_WAIT
every few milliseconds (as we do not have threads or proper access to the internal event loop). If I create an "empty" context without sessions or endpoints early on while this loop is running, we see errors from theselect()
call in coap_io.c if we start this application on Windows. In this application, we start client sessions in this context later on certain events.After comparing the documentation for
select()
on Windows [1] and Linux [2], it looks to me like the Windows version does not like being called without file descriptors/sockets. I applied this patch and it seems to work without error messages so far.I could add code in my wrapper to call
coap_io_process
only for contexts with active sockets but I think this patch might also benefit others. Maybe it would even make sense to skip more code in this function if the context has no sockets. What do you think?Thank you!
[1] https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-select
[2] https://man7.org/linux/man-pages/man2/select.2.html