casaroli opened a new pull request, #20648: URL: https://github.com/apache/nuttx/pull/20648
## Summary `select()` put a descriptor with `POLLERR` only in `exceptfds`. A caller that asked only for `readfds` or `writefds`, which is the usual case, did not see the error: `select()` returned 0, also with no timeout, where 0 means that the timeout expired. POSIX says that a descriptor is ready for reading (or writing) when the call would not block, "whether or not the function would transfer data successfully", so also when it would return an error. Linux reports `POLLERR` in the read and write sets. This PR reports `POLLERR` in `readfds` and `writefds`. `poll()` reports `POLLHUP` and `POLLERR` also when they were not asked for, so the PR sets only the bits of the sets that the caller asked for: before, a descriptor in `writefds` only could also appear in `readfds` on `POLLHUP`. `exceptfds` does not change. ## Impact `select()` callers that ask for `readfds` or `writefds` now see a descriptor with an error as ready, and the following `read()` or `write()` returns the error. `exceptfds` is as before. ## Testing `qemu-armv8a:nsh` (flat) with `CONFIG_PIPES=y` and the default `CONFIG_DEV_PIPE_NPOLLWAITERS=4`. A test program starts 6 threads that call `select()` with no timeout on the read end of one pipe, then writes 6 bytes. The pipe has 4 poll slots, so threads 5 and 6 get `POLLERR`: | | master | this PR | |---|---|---| | `select()` calls with no timeout that returned 0 | 2 of 6 | 0 of 6 | With this PR the two threads see the descriptor in `readfds`, and their `read()` waits for the data. `ostest` exits with status 0 on both. Build: `qemu-armv8a:knsh` and `lm3s6965-ek:qemu-flat`, no warnings. `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
