Skip to content

Commit

Permalink
tcp/close: Fix clean socket closure when lingering
Browse files Browse the repository at this point in the history
2.1.3-esp: 316cfc1 tcp/close: Fix clean socket closure when lignering
  • Loading branch information
david-cermak committed Sep 11, 2024
1 parent 88136ab commit 3f6b428
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/api/api_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ netconn_drain(struct netconn *conn)
/* Only tcp pcbs have an acceptmbox, so no need to check conn->type */
/* pcb might be set to NULL already by err_tcp() */
/* drain recvmbox */
#if ESP_LWIP
#if ESP_LWIP && LWIP_NETCONN_FULLDUPLEX
newconn->flags |= NETCONN_FLAG_MBOXINVALID;
#endif /* ESP_LWIP */
netconn_drain(newconn);
Expand Down Expand Up @@ -1032,7 +1032,11 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
if ((err == ERR_OK) && (tpcb != NULL))
#endif /* LWIP_SO_LINGER */
{
err = tcp_close(tpcb);
err = tcp_close_ext(tpcb,
#if LWIP_SO_LINGER
/* don't send RST yet if linger-wait-required */ linger_wait_required ? 0 :
#endif
1);
}
} else {
err = tcp_shutdown(tpcb, shut_rx, shut_tx);
Expand Down
8 changes: 7 additions & 1 deletion src/core/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ tcp_close_shutdown_fin(struct tcp_pcb *pcb)
*/
err_t
tcp_close(struct tcp_pcb *pcb)
{
return tcp_close_ext(pcb, 1);
}

err_t
tcp_close_ext(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
{
LWIP_ASSERT_CORE_LOCKED();

Expand All @@ -495,7 +501,7 @@ tcp_close(struct tcp_pcb *pcb)
tcp_set_flags(pcb, TF_RXCLOSED);
}
/* ... and close */
return tcp_close_shutdown(pcb, 1);
return tcp_close_shutdown(pcb, rst_on_unacked_data);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/include/lwip/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ struct tcp_pcb * tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog);

void tcp_abort (struct tcp_pcb *pcb);
err_t tcp_close (struct tcp_pcb *pcb);
err_t tcp_close_ext(struct tcp_pcb *pcb, u8_t rst_on_unacked_data);

err_t tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx);

err_t tcp_write (struct tcp_pcb *pcb, const void *dataptr, u16_t len,
Expand Down

0 comments on commit 3f6b428

Please sign in to comment.