[tcp|udp]_poll_eventhandler check psock_[tcp|udp]_cansend before report POLLOUT. Change the unbuffered psock_[tcp|udp]_cansend return OK to unify the code logic and remove the unnecessary [tcp|udp]_poll_txnotify call.

This commit is contained in:
Xiang Xiao 2019-11-24 10:30:48 -06:00 committed by Gregory Nutt
parent 673f812c4e
commit 98fc60eb75
4 changed files with 10 additions and 173 deletions

View file

@ -120,13 +120,9 @@ static uint16_t tcp_poll_eventhandler(FAR struct net_driver_s *dev,
eventset |= POLLIN & info->fds->events;
}
/* A poll is a sign that we are free to send data.
* REVISIT: This is bogus: If CONFIG_TCP_WRITE_BUFFERS=y then
* we never have to wait to send; otherwise, we always have to
* wait to send. Receiving a poll is irrelevant.
*/
/* A poll is a sign that we are free to send data. */
if ((flags & TCP_POLL) != 0)
if ((flags & TCP_POLL) != 0 && psock_tcp_cansend(info->psock) >= 0)
{
eventset |= (POLLOUT & info->fds->events);
}
@ -244,55 +240,6 @@ static inline void tcp_iob_work(FAR void *arg)
}
#endif
/****************************************************************************
* Name: tcp_poll_txnotify
*
* Description:
* Notify the appropriate device driver that we are have data ready to
* be sent (TCP)
*
* Input Parameters:
* psock - Socket state structure
*
* Returned Value:
* None
*
****************************************************************************/
#if !defined(CONFIG_NET_TCP_WRITE_BUFFERS) || !defined(CONFIG_IOB_NOTIFIER)
static inline void tcp_poll_txnotify(FAR struct socket *psock)
{
FAR struct tcp_conn_s *conn = psock->s_conn;
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
/* If both IPv4 and IPv6 support are enabled, then we will need to select
* the device driver using the appropriate IP domain.
*/
if (psock->s_domain == PF_INET)
#endif
{
/* Notify the device driver that send data is available */
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else /* if (psock->s_domain == PF_INET6) */
#endif /* CONFIG_NET_IPv4 */
{
/* Notify the device driver that send data is available */
DEBUGASSERT(psock->s_domain == PF_INET6);
netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
}
#endif /* CONFIG_NET_IPv6 */
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -464,8 +411,8 @@ int tcp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds)
#if defined(CONFIG_NET_TCP_WRITE_BUFFERS) && defined(CONFIG_IOB_NOTIFIER)
/* If (1) revents == 0, (2) write buffering is enabled, and (3) the
* POLLOUT event is needed, then setup to receive a notification an IOB
* is freed.
* POLLOUT event is needed, then setup to receive a notification when an
* IOB is freed.
*/
else if ((fds->events & POLLOUT) != 0)
@ -474,23 +421,6 @@ int tcp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds)
info->key = iob_notifier_setup(LPWORK, tcp_iob_work, info);
}
#else
/* If (1) the socket is in a bound state, (2) revents == 0, (3) write
* buffering is not enabled (determined by a configuration setting), and
* (4) the POLLOUT event is needed then request an immediate Tx poll from
* the device associated with the binding.
*/
else if (_SS_ISBOUND(psock->s_flags) && (fds->events & POLLOUT) != 0)
{
/* Note that the notification will fail if the socket is bound to
* INADDR_ANY or the IPv6 unspecified address! In that case the
* notification will fail.
*/
tcp_poll_txnotify(psock);
}
#endif
net_unlock();

View file

@ -824,7 +824,7 @@ errout:
* psock An instance of the internal socket structure.
*
* Returned Value:
* -ENOSYS (Function not implemented, always have to wait to send).
* OK (Always can send).
*
* Assumptions:
* None
@ -833,7 +833,7 @@ errout:
int psock_tcp_cansend(FAR struct socket *psock)
{
return -ENOSYS;
return OK;
}
#endif /* CONFIG_NET && CONFIG_NET_TCP && !CONFIG_NET_TCP_WRITE_BUFFERS */

View file

@ -120,13 +120,9 @@ static uint16_t udp_poll_eventhandler(FAR struct net_driver_s *dev,
eventset |= (POLLIN & info->fds->events);
}
/* A poll is a sign that we are free to send data.
* REVISIT: This is bogus: If CONFIG_UDP_WRITE_BUFFERS=y then
* we never have to wait to send; otherwise, we always have to
* wait to send. Receiving a poll is irrelevant.
*/
/* A poll is a sign that we are free to send data. */
if ((flags & UDP_POLL) != 0)
if ((flags & UDP_POLL) != 0 && psock_udp_cansend(info->psock) >= 0)
{
eventset |= (POLLOUT & info->fds->events);
}
@ -217,55 +213,6 @@ static inline void udp_iob_work(FAR void *arg)
}
#endif
/****************************************************************************
* Name: udp_poll_txnotify
*
* Description:
* Notify the appropriate device driver that we are have data ready to
* be sent (UDP)
*
* Input Parameters:
* psock - Socket state structure
*
* Returned Value:
* None
*
****************************************************************************/
#if !defined(CONFIG_NET_UDP_WRITE_BUFFERS) || !defined(CONFIG_IOB_NOTIFIER)
static inline void udp_poll_txnotify(FAR struct socket *psock)
{
FAR struct udp_conn_s *conn = psock->s_conn;
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
/* If both IPv4 and IPv6 support are enabled, then we will need to select
* the device driver using the appropriate IP domain.
*/
if (psock->s_domain == PF_INET)
#endif
{
/* Notify the device driver that send data is available */
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else /* if (psock->s_domain == PF_INET6) */
#endif /* CONFIG_NET_IPv4 */
{
/* Notify the device driver that send data is available */
DEBUGASSERT(psock->s_domain == PF_INET6);
netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
}
#endif /* CONFIG_NET_IPv6 */
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
@ -401,46 +348,6 @@ int udp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds)
info->key = iob_notifier_setup(LPWORK, udp_iob_work, info);
}
#else
/* If (1) the socket is in a bound state via bind() or via the
* UDP_BINDTODEVICE socket options, (2) revents == 0, (3) write buffering
* is not enabled (determined by a configuration setting), and (3) the
* POLLOUT event is needed then request an immediate Tx poll from the
* device associated with the binding.
*/
else if ((fds->events & POLLOUT) != 0)
{
/* Check if the socket has been bound to a local address (might be
* INADDR_ANY or the IPv6 unspecified address! In that case the
* notification will fail)
*/
if (_SS_ISBOUND(psock->s_flags))
{
udp_poll_txnotify(psock);
}
#ifdef CONFIG_NET_UDP_BINDTODEVICE
/* Check if the socket has been bound to a device interface index via
* the UDP_BINDTODEVICE socket option.
*/
else if (conn->boundto > 0)
{
/* Yes, find the device associated with the interface index */
FAR struct net_driver_s *dev = netdev_findbyindex(conn->boundto);
if (dev != NULL)
{
/* And request a poll from the device */
netdev_txnotify_dev(dev);
}
}
#endif
}
#endif
net_unlock();

View file

@ -588,7 +588,7 @@ errout_with_lock:
* psock An instance of the internal socket structure.
*
* Returned Value:
* -ENOSYS (Function not implemented, always have to wait to send).
* OK (Always can send).
*
* Assumptions:
* None
@ -597,7 +597,7 @@ errout_with_lock:
int psock_udp_cansend(FAR struct socket *psock)
{
return -ENOSYS;
return OK;
}
#endif /* CONFIG_NET_UDP */