net/callback: remove the assert check of conn instance
remove the connection assertion since the instance will be invalid if the network device has been taken down. net/netdev/netdev_ioctl.c: 1847 void netdev_ifdown(FAR struct net_driver_s *dev) 1848 { ... 1871 /* Notify clients that the network has been taken down */ 1872 1873 devif_dev_event(dev, NULL, NETDEV_DOWN); ... 1883 } Change-Id: I492b97b5ebe035ea67bbdd7ed635cb13d085e89c Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
parent
5dd5174722
commit
95be9eaf4b
@ -93,7 +93,7 @@ static uint16_t bluetooth_sendto_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
int hdrlen;
|
int hdrlen;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(pvpriv != NULL && dev != NULL && pvconn != NULL);
|
DEBUGASSERT(pvpriv != NULL && dev != NULL);
|
||||||
|
|
||||||
/* Ignore polls from non Bluetooth network drivers */
|
/* Ignore polls from non Bluetooth network drivers */
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ static uint16_t ieee802154_sendto_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
int hdrlen;
|
int hdrlen;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(pvpriv != NULL && dev != NULL && pvconn != NULL);
|
DEBUGASSERT(pvpriv != NULL && dev != NULL);
|
||||||
|
|
||||||
/* Ignore polls from non IEEE 802.15.4 network drivers */
|
/* Ignore polls from non IEEE 802.15.4 network drivers */
|
||||||
|
|
||||||
|
@ -312,6 +312,15 @@ static uint16_t tcp_send_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
return flags;
|
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.
|
/* 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.
|
* 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;
|
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",
|
ninfo("flags: %04x acked: %u sent: %u\n",
|
||||||
flags, sinfo->s_acked, sinfo->s_sent);
|
flags, sinfo->s_acked, sinfo->s_sent);
|
||||||
|
|
||||||
|
@ -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_close_s *pstate = (FAR struct tcp_close_s *)pvpriv;
|
||||||
FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn;
|
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_DISCONN_EVENTS:
|
||||||
* TCP_CLOSE: The remote host has closed the connection
|
* TCP_CLOSE: The remote host has closed the connection
|
||||||
|
@ -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 tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn;
|
||||||
FAR struct socket *psock = (FAR struct socket *)pvpriv;
|
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.
|
/* 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.
|
* 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 */
|
/* Check if we are being asked to retransmit data */
|
||||||
|
|
||||||
else if ((flags & TCP_REXMIT) != 0)
|
else if ((flags & TCP_REXMIT) != 0)
|
||||||
|
@ -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;
|
FAR struct sendfile_s *pstate = (FAR struct sendfile_s *)pvpriv;
|
||||||
int ret;
|
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 */
|
/* Check for a loss of connection */
|
||||||
|
|
||||||
if ((flags & TCP_DISCONN_EVENTS) != 0)
|
if ((flags & TCP_DISCONN_EVENTS) != 0)
|
||||||
@ -276,6 +263,20 @@ static uint16_t sendfile_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
goto end_wait;
|
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
|
/* 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)
|
* 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
|
* the outgoing packet is available for our use. In this case, we are
|
||||||
|
@ -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 udp_conn_s *conn = (FAR struct udp_conn_s *)pvconn;
|
||||||
FAR struct socket *psock = (FAR struct socket *)pvpriv;
|
FAR struct socket *psock = (FAR struct socket *)pvpriv;
|
||||||
|
|
||||||
DEBUGASSERT(dev != NULL && conn != NULL && psock != NULL);
|
DEBUGASSERT(dev != 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
ninfo("flags: %04x\n", flags);
|
ninfo("flags: %04x\n", flags);
|
||||||
|
|
||||||
@ -399,7 +383,24 @@ static uint16_t sendto_eventhandler(FAR struct net_driver_s *dev,
|
|||||||
* the next transfer.
|
* 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;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user