From 9e73216bf20060a1a4de1b04a19fd9cd4b37c697 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 19 Oct 2017 16:45:00 -0600 Subject: [PATCH] net/tcp: Same change to tcp_send_buffered.c probably also applies to sixlowpan_tcpsend.c and inet_recvfrom.c --- net/inet/inet_recvfrom.c | 17 ++++++++++++++--- net/sixlowpan/sixlowpan_tcpsend.c | 20 +++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/net/inet/inet_recvfrom.c b/net/inet/inet_recvfrom.c index e4660f82e6..b42c971a3e 100644 --- a/net/inet/inet_recvfrom.c +++ b/net/inet/inet_recvfrom.c @@ -735,11 +735,22 @@ static uint16_t inet_tcp_eventhandler(FAR struct net_driver_s *dev, else if ((flags & TCP_DISCONN_EVENTS) != 0) { - ninfo("Lost connection\n"); + FAR struct socket *psock = pstate->ir_sock; - /* Handle loss-of-connection event */ + nwarn("WARNING: Lost connection\n"); - tcp_lost_connection(pstate->ir_sock, pstate->ir_cb, flags); + /* We could get here recursively through the callback actions of + * tcp_lost_connection(). So don't repeat that action if we have + * already been disconnected. + */ + + DEBUGASSERT(psock != NULL); + if (_SS_ISCONNECTED(psock->s_flags)) + { + /* Handle loss-of-connection event */ + + tcp_lost_connection(psock, pstate->ir_cb, flags); + } /* Check if the peer gracefully closed the connection. */ diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 2c1ceb3877..4fa8788e2b 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -439,11 +439,25 @@ static uint16_t tcp_send_eventhandler(FAR struct net_driver_s *dev, else if ((flags & TCP_DISCONN_EVENTS) != 0) { - ninfo("Lost connection\n"); + FAR struct socket *psock = sinfo->s_sock; - /* Report the disconnection event to all socket clones */ + nwarn("WARNING: Lost connection\n"); + + /* We could get here recursively through the callback actions of + * tcp_lost_connection(). So don't repeat that action if we have + * already been disconnected. + */ + + DEBUGASSERT(psock != NULL); + if (_SS_ISCONNECTED(psock->s_flags)) + { + /* Report the disconnection event to all socket clones */ + + tcp_lost_connection(psock, sinfo->s_cb, flags); + } + + /* Report not connected to the sender */ - tcp_lost_connection(sinfo->s_sock, sinfo->s_cb, flags); sinfo->s_result = -ENOTCONN; goto end_wait; }