UDP Networking: Misc fixes to get the last changes working + cleanup

This commit is contained in:
Gregory Nutt
2015-05-29 14:32:56 -06:00
parent fa8b7c19b7
commit 0bdf2d5360
6 changed files with 29 additions and 68 deletions
+17 -5
View File
@@ -42,6 +42,7 @@
#include <time.h> #include <time.h>
#include <semaphore.h> #include <semaphore.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#include <debug.h> #include <debug.h>
#include <netinet/in.h> #include <netinet/in.h>
@@ -67,7 +68,7 @@
/* List of tasks waiting for ARP events */ /* List of tasks waiting for ARP events */
static struct arp_notify_s *g_arp_waiters; static FAR struct arp_notify_s *g_arp_waiters;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@@ -176,6 +177,7 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout)
{ {
struct timespec abstime; struct timespec abstime;
irqstate_t flags; irqstate_t flags;
int errcode;
int ret; int ret;
/* And wait for the ARP response (or a timeout). Interrupts will be re- /* And wait for the ARP response (or a timeout). Interrupts will be re-
@@ -193,11 +195,21 @@ int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout)
abstime.tv_nsec -= 1000000000; abstime.tv_nsec -= 1000000000;
} }
/* REVISIT: If net_timedwait() is awakened with signal, we will return /* Wait to get either the correct response or a timeout. */
* the wrong error code.
*/ do
{
/* The only errors that we expect would be if the abstime timeout
* expires or if the wait were interrupted by a signal.
*/
ret = net_timedwait(&notify->nt_sem, &abstime);
errcode = ((ret < 0) ? errno : 0);
}
while (ret < 0 && errcode == EINTR);
/* Then get the real result of the transfer */
(void)net_timedwait(&notify->nt_sem, &abstime);
ret = notify->nt_result; ret = notify->nt_result;
/* Remove our wait structure from the list (we may no longer be at the /* Remove our wait structure from the list (we may no longer be at the
+4 -2
View File
@@ -293,7 +293,7 @@ int arp_send(in_addr_t ipaddr)
state.snd_cb = arp_callback_alloc(dev); state.snd_cb = arp_callback_alloc(dev);
if (!state.snd_cb) if (!state.snd_cb)
{ {
ndbg("ERROR: Failed to allocate a cllback\n"); ndbg("ERROR: Failed to allocate a callback\n");
ret = -ENOMEM; ret = -ENOMEM;
goto errout_with_lock; goto errout_with_lock;
} }
@@ -373,6 +373,7 @@ int arp_send(in_addr_t ipaddr)
{ {
/* Break out on a send failure */ /* Break out on a send failure */
ndbg("ERROR: Send failed: %d\n", ret);
break; break;
} }
@@ -390,7 +391,7 @@ int arp_send(in_addr_t ipaddr)
* is received. Otherwise, it will return -ETIMEDOUT. * is received. Otherwise, it will return -ETIMEDOUT.
*/ */
if (ret == OK) if (ret >= OK)
{ {
/* Break out if arp_wait() fails */ /* Break out if arp_wait() fails */
@@ -400,6 +401,7 @@ int arp_send(in_addr_t ipaddr)
/* Increment the retry count */ /* Increment the retry count */
state.snd_retries++; state.snd_retries++;
ndbg("ERROR: arp_wait failed: %d\n", ret);
} }
sem_destroy(&state.snd_sem); sem_destroy(&state.snd_sem);
+2 -2
View File
@@ -134,8 +134,8 @@ FAR struct devif_callback_s *
return NULL; return NULL;
} }
ret->nxtdev = dev->d_devcb; ret->nxtdev = dev->d_devcb;
dev->d_devcb = ret; dev->d_devcb = ret;
} }
/* Add the newly allocated instance to the head of the specified list */ /* Add the newly allocated instance to the head of the specified list */
+1 -1
View File
@@ -226,7 +226,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
if (nsent < 0) if (nsent < 0)
{ {
ndbg("ERROR: Unix domain sendto() failed: %ld\n", (long)nsent); ndbg("ERROR: UDP or Unix domain sendto() failed: %ld\n", (long)nsent);
err = -nsent; err = -nsent;
goto errout; goto errout;
} }
+4 -57
View File
@@ -303,61 +303,6 @@ static uint16_t sendto_interrupt(FAR struct net_driver_s *dev, FAR void *conn,
return flags; return flags;
} }
/****************************************************************************
* Function: sendto_txnotify
*
* Description:
* Notify the appropriate device driver that we are have data ready to
* be send (UDP)
*
* Parameters:
* psock - Socket state structure
* conn - The UDP connection structure
*
* Returned Value:
* None
*
****************************************************************************/
static inline void sendto_txnotify(FAR struct socket *psock,
FAR struct udp_conn_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 */
#ifdef CONFIG_NETDEV_MULTINIC
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
#else
netdev_ipv4_txnotify(conn->u.ipv4.raddr);
#endif
}
#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);
#ifdef CONFIG_NETDEV_MULTINIC
netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
#else
netdev_ipv6_txnotify(conn->u.ipv6.raddr);
#endif
}
#endif /* CONFIG_NET_IPv6 */
}
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -430,7 +375,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
if (ret < 0) if (ret < 0)
{ {
ndbg("ERROR: Not reachable\n"); ndbg("ERROR: Peer not reachable\n");
return -ENETUNREACH; return -ENETUNREACH;
} }
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */ #endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
@@ -474,6 +419,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
ret = udp_connect(conn, to); ret = udp_connect(conn, to);
if (ret < 0) if (ret < 0)
{ {
ndbg("ERROR: udp_connect failed: %d\n", ret);
goto errout_with_lock; goto errout_with_lock;
} }
@@ -484,6 +430,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
dev = udp_find_raddr_device(conn); dev = udp_find_raddr_device(conn);
if (dev == NULL) if (dev == NULL)
{ {
ndbg("ERROR: udp_find_raddr_device failed\n");
ret = -ENETUNREACH; ret = -ENETUNREACH;
goto errout_with_lock; goto errout_with_lock;
} }
@@ -499,7 +446,7 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
/* Notify the device driver of the availability of TX data */ /* Notify the device driver of the availability of TX data */
sendto_txnotify(psock, conn); netdev_txnotify_dev(dev);
/* Wait for either the receive to complete or for an error/timeout to occur. /* Wait for either the receive to complete or for an error/timeout to occur.
* NOTES: (1) net_lockedwait will also terminate if a signal is received, (2) * NOTES: (1) net_lockedwait will also terminate if a signal is received, (2)
+1 -1
View File
@@ -218,7 +218,7 @@ int net_timedwait(sem_t *sem, FAR const struct timespec *abstime)
} }
else else
{ {
/* Wait as long as necessary to get the lot */ /* Wait as long as necessary to get the lock */
ret = sem_wait(sem); ret = sem_wait(sem);
} }