@@ -3137,7 +3137,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
31373137 * the TCP context and put the connection into
31383138 * active close (TCP_FIN_WAIT_1).
31393139 */
3140- net_tcp_put (conn -> context );
3140+ net_tcp_put (conn -> context , false );
31413141break ;
31423142}
31433143
@@ -3690,7 +3690,7 @@ static enum net_verdict tcp_in(struct tcp *conn, struct net_pkt *pkt)
36903690}
36913691
36923692/* Active connection close: send FIN and go to FIN_WAIT_1 state */
3693- int net_tcp_put (struct net_context * context )
3693+ int net_tcp_put (struct net_context * context , bool force_close )
36943694{
36953695struct tcp * conn = context -> tcp ;
36963696
@@ -3715,24 +3715,41 @@ int net_tcp_put(struct net_context *context)
37153715
37163716/* How long to wait until all the data has been sent?
37173717 */
3718- k_work_reschedule_for_queue (& tcp_work_q ,
3719- & conn -> send_data_timer ,
3720- K_MSEC (TCP_RTO_MS ));
3718+ if (!force_close ) {
3719+ k_work_reschedule_for_queue (& tcp_work_q ,
3720+ & conn -> send_data_timer ,
3721+ K_MSEC (TCP_RTO_MS ));
3722+ } else {
3723+ k_work_cancel_delayable (& conn -> send_data_timer );
3724+
3725+ keep_alive_timer_stop (conn );
3726+ tcp_conn_close (conn , - ENETRESET );
3727+ }
3728+
37213729} else {
3722- NET_DBG ("[%p] TCP connection in %s close, "
3723- "not disposing yet (waiting %dms)" ,
3724- conn , "active" , tcp_max_timeout_ms );
3725- k_work_reschedule_for_queue (& tcp_work_q ,
3726- & conn -> fin_timer ,
3727- FIN_TIMEOUT );
3730+ if (!force_close ) {
3731+ NET_DBG ("[%p] TCP connection in %s close, "
3732+ "not disposing yet (waiting %dms)" ,
3733+ conn , "active" , tcp_max_timeout_ms );
3734+ k_work_reschedule_for_queue (& tcp_work_q ,
3735+ & conn -> fin_timer ,
3736+ FIN_TIMEOUT );
37283737
3729- tcp_out (conn , FIN | ACK );
3730- conn_seq (conn , + 1 );
3731- tcp_setup_retransmission (conn );
3738+ tcp_out (conn , FIN | ACK );
3739+ conn_seq (conn , + 1 );
3740+ tcp_setup_retransmission (conn );
37323741
3733- conn_state (conn , TCP_FIN_WAIT_1 );
3742+ conn_state (conn , TCP_FIN_WAIT_1 );
37343743
3735- keep_alive_timer_stop (conn );
3744+ keep_alive_timer_stop (conn );
3745+ } else {
3746+ NET_DBG ("[%p] TCP connection in %s close, "
3747+ "disposing immediately" ,
3748+ conn , "active" );
3749+
3750+ keep_alive_timer_stop (conn );
3751+ tcp_conn_close (conn , - ENETRESET );
3752+ }
37363753}
37373754} else if (conn -> in_connect ) {
37383755conn -> in_connect = false;
@@ -4411,7 +4428,7 @@ enum net_verdict tp_input(struct net_conn *net_conn,
44114428if (is ("CLOSE2" , tp -> op )) {
44124429struct tcp * conn =
44134430(void * )sys_slist_peek_head (& tcp_conns );
4414- net_tcp_put (conn -> context );
4431+ net_tcp_put (conn -> context , false );
44154432}
44164433if (is ("RECV" , tp -> op )) {
44174434#define HEXSTR_SIZE 64
0 commit comments