diff --git a/net/bluetooth/bluetooth_sendto.c b/net/bluetooth/bluetooth_sendto.c index 7223078cf4..0bb1ab97f5 100644 --- a/net/bluetooth/bluetooth_sendto.c +++ b/net/bluetooth/bluetooth_sendto.c @@ -93,7 +93,7 @@ static uint16_t bluetooth_sendto_eventhandler(FAR struct net_driver_s *dev, int hdrlen; int ret; - DEBUGASSERT(pvpriv != NULL && dev != NULL && pvconn != NULL); + DEBUGASSERT(pvpriv != NULL && dev != NULL); /* Ignore polls from non Bluetooth network drivers */ diff --git a/net/ieee802154/ieee802154_sendto.c b/net/ieee802154/ieee802154_sendto.c index 05dae325c2..391e4c63d7 100644 --- a/net/ieee802154/ieee802154_sendto.c +++ b/net/ieee802154/ieee802154_sendto.c @@ -282,7 +282,7 @@ static uint16_t ieee802154_sendto_eventhandler(FAR struct net_driver_s *dev, int hdrlen; int ret; - DEBUGASSERT(pvpriv != NULL && dev != NULL && pvconn != NULL); + DEBUGASSERT(pvpriv != NULL && dev != NULL); /* Ignore polls from non IEEE 802.15.4 network drivers */ diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 28d20f9fd5..bbc32c7087 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -312,6 +312,15 @@ static uint16_t tcp_send_eventhandler(FAR struct net_driver_s *dev, return flags; } + /* Check if the IEEE802.15.4 network driver went down */ + + if ((flags & NETDEV_DOWN) != 0) + { + nwarn("WARNING: Device is down\n"); + sinfo->s_result = -ENOTCONN; + goto end_wait; + } + /* The TCP socket is connected and, hence, should be bound to a device. * Make sure that the polling device is the one that we are bound to. */ @@ -323,15 +332,6 @@ static uint16_t tcp_send_eventhandler(FAR struct net_driver_s *dev, return flags; } - /* Check if the IEEE802.15.4 network driver went down */ - - if ((flags & NETDEV_DOWN) != 0) - { - nwarn("WARNING: Device is down\n"); - sinfo->s_result = -ENOTCONN; - goto end_wait; - } - ninfo("flags: %04x acked: %u sent: %u\n", flags, sinfo->s_acked, sinfo->s_sent); diff --git a/net/tcp/tcp_close.c b/net/tcp/tcp_close.c index 2d57588fb3..15927a60f2 100644 --- a/net/tcp/tcp_close.c +++ b/net/tcp/tcp_close.c @@ -81,9 +81,9 @@ static uint16_t tcp_close_eventhandler(FAR struct net_driver_s *dev, FAR struct tcp_close_s *pstate = (FAR struct tcp_close_s *)pvpriv; FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; - DEBUGASSERT(pstate != NULL && conn != NULL); + DEBUGASSERT(pstate != NULL); - ninfo("conn: %p flags: %04x\n", conn, flags); + ninfo("flags: %04x\n", flags); /* TCP_DISCONN_EVENTS: * TCP_CLOSE: The remote host has closed the connection diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 598392eca8..c2695513ba 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -327,6 +327,30 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; FAR struct socket *psock = (FAR struct socket *)pvpriv; + /* Check for a loss of connection */ + + if ((flags & TCP_DISCONN_EVENTS) != 0) + { + ninfo("Lost connection: %04x\n", 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. + */ + + if (psock->s_conn != NULL && _SS_ISCONNECTED(psock->s_flags)) + { + /* Report not connected */ + + tcp_lost_connection(psock, psock->s_sndcb, flags); + } + + /* Free write buffers and terminate polling */ + + psock_lost_connection(psock, psock->s_conn, !!(flags & NETDEV_DOWN)); + return flags; + } + /* The TCP socket is connected and, hence, should be bound to a device. * Make sure that the polling device is the one that we are bound to. */ @@ -494,30 +518,6 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev, } } - /* Check for a loss of connection */ - - else if ((flags & TCP_DISCONN_EVENTS) != 0) - { - ninfo("Lost connection: %04x\n", 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. - */ - - if (psock->s_conn != NULL && _SS_ISCONNECTED(psock->s_flags)) - { - /* Report not connected */ - - tcp_lost_connection(psock, psock->s_sndcb, flags); - } - - /* Free write buffers and terminate polling */ - - psock_lost_connection(psock, conn, !!(flags & NETDEV_DOWN)); - return flags; - } - /* Check if we are being asked to retransmit data */ else if ((flags & TCP_REXMIT) != 0) diff --git a/net/tcp/tcp_sendfile.c b/net/tcp/tcp_sendfile.c index d9c4640e67..a1676caa4b 100644 --- a/net/tcp/tcp_sendfile.c +++ b/net/tcp/tcp_sendfile.c @@ -236,19 +236,6 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev, FAR struct sendfile_s *pstate = (FAR struct sendfile_s *)pvpriv; int ret; - /* The TCP socket is connected and, hence, should be bound to a device. - * Make sure that the polling device is the own that we are bound to. - */ - - DEBUGASSERT(conn->dev != NULL); - if (dev != conn->dev) - { - return flags; - } - - ninfo("flags: %04x acked: %d sent: %d\n", - flags, pstate->snd_acked, pstate->snd_sent); - /* Check for a loss of connection */ if ((flags & TCP_DISCONN_EVENTS) != 0) @@ -276,6 +263,20 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev, goto end_wait; } + /* The TCP socket is connected and, hence, should be bound to a device. + * Make sure that the polling device is the own that we are bound to. + */ + + DEBUGASSERT(conn); + DEBUGASSERT(conn->dev != NULL); + if (dev != conn->dev) + { + return flags; + } + + ninfo("flags: %04x acked: %d sent: %d\n", + flags, pstate->snd_acked, pstate->snd_sent); + /* We get here if (1) not all of the data has been ACKed, (2) we have been * asked to retransmit data, (3) the connection is still healthy, and (4) * the outgoing packet is available for our use. In this case, we are diff --git a/net/udp/udp_sendto_buffered.c b/net/udp/udp_sendto_buffered.c index aee41e4d18..d1479ff0f5 100644 --- a/net/udp/udp_sendto_buffered.c +++ b/net/udp/udp_sendto_buffered.c @@ -369,23 +369,7 @@ static uint16_t sendto_eventhandler(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn = (FAR struct udp_conn_s *)pvconn; FAR struct socket *psock = (FAR struct socket *)pvpriv; - DEBUGASSERT(dev != NULL && conn != NULL && psock != NULL); - - /* The UDP socket should be bound to a device. Make sure that the polling - * device is the one that we are bound to. - * - * REVISIT: There is a logical error here for the case where there are - * multiple network devices. In that case, the packets may need to be sent - * in a different order than they were queued. The packet we may need to - * send on this device may not be at the head of the list. Forcing FIFO - * packet transmission could degrade performance! - */ - - DEBUGASSERT(conn->dev != NULL); - if (dev != conn->dev) - { - return flags; - } + DEBUGASSERT(dev != NULL && psock != NULL); ninfo("flags: %04x\n", flags); @@ -399,7 +383,24 @@ static uint16_t sendto_eventhandler(FAR struct net_driver_s *dev, * the next transfer. */ - sendto_writebuffer_release(psock, conn); + sendto_writebuffer_release(psock, psock->s_conn); + return flags; + } + + /* The UDP socket should be bound to a device. Make sure that the polling + * device is the one that we are bound to. + * + * REVISIT: There is a logical error here for the case where there are + * multiple network devices. In that case, the packets may need to be sent + * in a different order than they were queued. The packet we may need to + * send on this device may not be at the head of the list. Forcing FIFO + * packet transmission could degrade performance! + */ + + DEBUGASSERT(conn != NULL); + DEBUGASSERT(conn->dev != NULL); + if (dev != conn->dev) + { return flags; }