Skip to content

Commit

Permalink
net/tcp: Set SO_ERROR for poll error in setup
Browse files Browse the repository at this point in the history
Normally, `SO_ERROR` for disconn events will be set by `tcp_poll_eventhandler`, but when the socket is closed before poll, we should also set the `SO_ERROR`.

On Linux, `tcp_poll` returns `EPOLLERR` event when `sk->sk_err` has value but doesn't let `poll` fail (doesn't set `errno`). https://github.com/torvalds/linux/blob/v6.5/net/ipv4/tcp.c#L594-L596
Note: `sk->sk_err` can be get by socket option `SO_ERROR` on Linux, so `POLLERR` will always be together with `SO_ERROR`.

Common libs like curl may try to read `SO_ERROR` on `POLLERR`.

Signed-off-by: Zhe Weng <[email protected]>
  • Loading branch information
wengzhe authored and xiaoxiang781216 committed Sep 14, 2023
1 parent e4721ce commit 7c42238
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions net/tcp/tcp_netpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ int tcp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds)
* exceptional event.
*/

_SO_CONN_SETERRNO(conn, ENOTCONN);
eventset |= POLLERR | POLLHUP;
}
else if (_SS_ISCONNECTED(conn->sconn.s_flags) &&
Expand Down

0 comments on commit 7c42238

Please sign in to comment.