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 5e96fc59f133c8ef4812da3b43dd018c30a7d644 Author: Marco Casaroli <[email protected]> AuthorDate: Wed Nov 18 17:16:05 2026 +0100 Documentation/os/networking: Describe how a closed TCP connection ends. The FIN of close() and shutdown(SHUT_WR) follows the queued data, a close() with unread data or with SO_LINGER 0 sends a RST, a closing connection keeps one callback, a device that goes down closes it, and the oldest closing connection is freed when no connection or callback is free. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- Documentation/os/networking/tcp_state_machine.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Documentation/os/networking/tcp_state_machine.rst b/Documentation/os/networking/tcp_state_machine.rst index 5a19607c2c4..1529bae0dfe 100644 --- a/Documentation/os/networking/tcp_state_machine.rst +++ b/Documentation/os/networking/tcp_state_machine.rst @@ -149,6 +149,19 @@ sends FIN and transitions: -> TCP_TIME_WAIT (FIN from peer) -> TCP_CLOSED (timer expiry) +The FIN goes after the data that the application queued before ``close()`` +or ``shutdown(SHUT_WR)``. A ``close()`` with received data that the +application did not read, or with ``SO_LINGER`` on and a time of zero, sends +a RST instead and drops the queued data (RFC 1122, section 4.2.2.13). + +After ``close()`` the connection keeps one callback (``tcp_close.c``) until it +ends; it is then freed. When the device of the connection goes down, the +connection is closed at once. When ``socket()`` or a new connection from a +listener finds no free connection structure, or ``close()`` finds no free +callback, the oldest connection that no socket uses and that only waits for +the end of its close (for example in ``TCP_TIME_WAIT``) is freed to make room +(``tcp_reclaim()`` in ``tcp_conn.c``). + Simultaneous close ------------------
