From a4eeaac87ca38a21a7515d5512599846ed9fdc0b Mon Sep 17 00:00:00 2001 From: Brendan McDonnell <35789100+bmcdonnell@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:47:14 -0400 Subject: [PATCH] When SO_LINGER is enabled w/ linger time = 0, do hard disconnect regardless of whether there's any pending or unacked data References: - Wright & Stevens, "TCP/IP Illustrated, Volume 2" - 30.4. tcp_disconnect Function - Figure 30.12. tcp_disconnect function: initiate TCP disconnect. - "Hard disconnect" section - UNIX Network Programming / Volume 1, Third Edition: The Sockets Networking API (aka "UNP") - 7.5 Generic Socket Options - "SO_LINGER Socket Option" section --- src/api/api_msg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 8092be96..f0e0b5c8 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -981,14 +981,14 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM) #if LWIP_SO_LINGER /* check linger possibilities before calling tcp_close */ err = ERR_OK; - /* linger enabled/required at all? (i.e. is there untransmitted data left?) */ - if ((conn->linger >= 0) && (conn->pcb.tcp->unsent || conn->pcb.tcp->unacked)) { + /* linger enabled? */ + if (conn->linger >= 0) { if ((conn->linger == 0)) { - /* data left but linger prevents waiting */ + /* 0-timeout linger prevents waiting */ tcp_abort(tpcb); tpcb = NULL; - } else if (conn->linger > 0) { - /* data left and linger says we should wait */ + } else if (conn->pcb.tcp->unsent || conn->pcb.tcp->unacked) { + /* data left and nonzero linger says we should wait */ if (netconn_is_nonblocking(conn)) { /* data left on a nonblocking netconn -> cannot linger */ err = ERR_WOULDBLOCK;