This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 678ef8f0f301fb6ebabf19db9ddb7a9d11bc707c Author: Marco Casaroli <[email protected]> AuthorDate: Tue Nov 17 21:57:40 2026 +0100 net/tcp: Send a RST, not a FIN, at an abortive close. close() with SO_LINGER on and a time of zero is an abortive close (POSIX, Linux): the connection is reset, the queued data is dropped, and the peer gets ECONNRESET. close() only set the linger timeout and left the RST to tcp_timer() at the next poll. An event before that poll went to tcp_close_eventhandler(), which handled it as a graceful close: on an ACK with nothing queued it sent a FIN, and the peer read end-of-file before the RST; with data queued, the send callback could still send it. Now an abortive close resets the connection at the first event of the close handler, as for unread data. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- net/tcp/tcp_close.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/net/tcp/tcp_close.c b/net/tcp/tcp_close.c index cef0a25c387..c74911a5f67 100644 --- a/net/tcp/tcp_close.c +++ b/net/tcp/tcp_close.c @@ -66,6 +66,27 @@ static void tcp_close_work(FAR void *param) } } +/**************************************************************************** + * Name: tcp_close_abortive + * + * Description: + * Return true if the close is abortive: SO_LINGER is on with a time of + * zero. POSIX and Linux: the connection is then reset (RST), the queued + * data is dropped, and no FIN is sent. + * + ****************************************************************************/ + +static bool tcp_close_abortive(FAR struct tcp_conn_s *conn) +{ +#ifdef CONFIG_NET_SOLINGER + return _SO_GETOPT(conn->sconn.s_options, SO_LINGER) && + conn->sconn.s_linger == 0; +#else + UNUSED(conn); + return false; +#endif +} + /**************************************************************************** * Name: tcp_close_eventhandler ****************************************************************************/ @@ -120,10 +141,12 @@ static uint32_t tcp_close_eventhandler(FAR struct net_driver_s *dev, * close, ends the connection with a RST at once (RFC 1122, section * 4.2.2.13), also while our own data waits to be sent: the peer may * wait for us to read before it reads, and the two connections would - * keep their buffers for ever. + * keep their buffers for ever. An abortive close (SO_LINGER with a + * time of zero) also sends a RST at once, not a FIN. */ - else if (conn->readahead != NULL || (flags & TCP_NEWDATA) != 0) + else if (conn->readahead != NULL || (flags & TCP_NEWDATA) != 0 || + tcp_close_abortive(conn)) { #ifdef CONFIG_NET_TCP_WRITE_BUFFERS if (conn->sndcb != NULL)
