cederom commented on PR #4166:
URL: https://github.com/apache/nuttx-apps/pull/4166#issuecomment-7247860902
- **Current master (without apache/nuttx#22429):** after `EINTR` the
blocking socket is neither connected nor connecting, so `tcp_pollsetup()`
returns `POLLERR|POLLHUP` at once and sets `SO_ERROR` to `ENOTCONN`. webclient
now fails with `-ENOTCONN` instead of taking `EISCONN` from a connection that
never completed as success. This is better than before even without the kernel
PR.
- **With apache/nuttx#22429:** `_SS_ISCONNECTING` is kept after `EINTR`,
`tcp_pollsetup()` arms `TCP_CONNECTED`, and `poll(POLLOUT)` + `SO_ERROR` gives
the result of the handshake, as on Linux.
- The non-blocking path is not affected: `EINTR` can't come from a
non-blocking `connect()`, and the `EINPROGRESS`/`EALREADY` handling in
`errout_with_errno` is unchanged.
- The first commit only adds blank lines (10 lines, nothing else changes).
A few small points:
1. **Stale errno in the error log.** After `wget_waitconnect()` the error
comes from `SO_ERROR` (or `-ETIMEDOUT`), and `errno` still holds `EINTR` from
`connect()`. So the existing
```c
nerr("ERROR: connect failed: %d\n", errno);
```
now prints `4` for a refused or timed-out connection. Could you print
`ret` instead? That is also correct for the other paths, where `ret == -errno`.
2. **The timeout restarts on every signal.** In
```c
do
{
ret = poll(&pfd, 1, timeout > 0 ? timeout * 1000 : -1);
}
while (ret < 0 && errno == EINTR);
```
each `EINTR` starts the full `timeout_sec` again. Signals that arrive
periodically are the likely reason `connect()` was interrupted in the first
place, so the wait can run well past `timeout_sec`. It is still bounded,
because the TCP stack ends the handshake by itself. With a deadline from
`clock_gettime(CLOCK_MONOTONIC)`, the remaining time could be passed on each
retry. Also, the total wait is now up to the `SO_SNDTIMEO` time already spent
in `connect()` plus another `timeout_sec`. Fine with me, but maybe worth a word
in the comment.
3. **Nit:** `timeout * 1000` overflows `int` for `timeout_sec > INT_MAX /
1000` (about 24 days). It's unlikely to happen, but a clamp costs nothing.
4. **Nit:** the HTTPS path (`tls_ops->connect()`) does its own `connect()`
and is not covered here. Fine to keep out of scope, but it may be worth a note
in the PR description so nobody assumes HTTPS is fixed too.
With (1) fixed I'm happy to approve. (2) to (4) are optional.
--
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]