Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: tcp: When closing the connection send FIN immediately #19747

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions subsys/net/ip/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,11 @@ int net_tcp_send_pkt(struct net_pkt *pkt)
return net_send_data(pkt);
}

static void flush_queue(struct net_context *context)
{
(void)net_tcp_send_data(context, NULL, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment to this function says:

        /* For now, just send all queued data synchronously.  Need to
         * add window handling and retry/ACK logic.
         */

So, it still would be a workaround, not a solution, and could lead to silent data loss.

}

static void restart_timer(struct net_tcp *tcp)
{
if (!sys_slist_is_empty(&tcp->sent_list)) {
Expand Down Expand Up @@ -1134,6 +1139,11 @@ bool net_tcp_ack_received(struct net_context *ctx, u32_t ack)
*/
if (valid_ack) {
restart_timer(ctx->tcp);

/* Flush anything pending. This is important as if there
* is FIN waiting in the queue, it gets sent asap.
*/
flush_queue(ctx);
}

return true;
Expand Down Expand Up @@ -1377,6 +1387,7 @@ int net_tcp_recv(struct net_context *context, net_context_recv_cb_t cb,
static void queue_fin(struct net_context *ctx)
{
struct net_pkt *pkt = NULL;
bool flush = false;
int ret;

ret = net_tcp_prepare_segment(ctx->tcp, NET_TCP_FIN, NULL, 0,
Expand All @@ -1385,7 +1396,15 @@ static void queue_fin(struct net_context *ctx)
return;
}

if (sys_slist_is_empty(&ctx->tcp->sent_list)) {
flush = true;
}

net_tcp_queue_pkt(ctx, pkt);

if (flush) {
flush_queue(ctx);
}
}

int net_tcp_put(struct net_context *context)
Expand Down