summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-01-17 08:33:14 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-01-17 08:33:14 -0600
commit2a8999e74ac1132918fc66d0f8eed5fb20d25fa4 (patch)
tree73e736b17b4885d8b5bfcc70301bff1cfa6ab230 /nuttx
parent32856f9401ff5cf603128d50c8884d89be952257 (diff)
downloadpx4-nuttx-2a8999e74ac1132918fc66d0f8eed5fb20d25fa4.tar.gz
px4-nuttx-2a8999e74ac1132918fc66d0f8eed5fb20d25fa4.tar.bz2
px4-nuttx-2a8999e74ac1132918fc66d0f8eed5fb20d25fa4.zip
net/socket and net/tcp: When we are ready to receive data or when we have outgoing data ready to be sent, we need to the notify the appropriate device driver of this condition. The notifying socket will be configured as either PF_INET or PF_INET6 and must look up the correct driver using the correct IP domain.
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/net/socket/net_close.c61
-rw-r--r--nuttx/net/socket/net_sendfile.c61
-rw-r--r--nuttx/net/socket/recvfrom.c91
-rw-r--r--nuttx/net/socket/sendto.c63
-rw-r--r--nuttx/net/tcp/tcp_send_buffered.c61
-rw-r--r--nuttx/net/tcp/tcp_send_unbuffered.c61
6 files changed, 361 insertions, 37 deletions
diff --git a/nuttx/net/socket/net_close.c b/nuttx/net/socket/net_close.c
index 618c1f7f5..4a8c2d464 100644
--- a/nuttx/net/socket/net_close.c
+++ b/nuttx/net/socket/net_close.c
@@ -258,6 +258,61 @@ end_wait:
#endif /* CONFIG_NET_TCP */
/****************************************************************************
+ * Function: netclose_txnotify
+ *
+ * Description:
+ * Notify the appropriate device driver that we are have data ready to
+ * be send (TCP)
+ *
+ * Parameters:
+ * psock - Socket state structure
+ * conn - The TCP connection structure
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void netclose_txnotify(FAR struct socket *psock,
+ FAR struct tcp_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->domain == PF_INET)
+#endif
+ {
+ /* Notify the device driver that send data is available */
+
+#ifdef CONFIG_NET_MULTILINK
+ 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->domain == PF_INET6) */
+#endif /* CONFIG_NET_IPv4 */
+ {
+ /* Notify the device driver that send data is available */
+
+ DEBUGASSERT(psock->domain == PF_INET6);
+#ifdef CONFIG_NET_MULTILINK
+ netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
+#else
+ netdev_ipv6_txnotify(conn->u.ipv6.raddr);
+#endif
+ }
+#endif /* CONFIG_NET_IPv6 */
+}
+
+/****************************************************************************
* Function: netclose_disconnect
*
* Description:
@@ -357,11 +412,7 @@ static inline int netclose_disconnect(FAR struct socket *psock)
/* Notify the device driver of the availability of TX data */
-#ifdef CONFIG_NET_MULTILINK
- netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
-#else
- netdev_ipv4_txnotify(conn->u.ipv4.raddr);
-#endif
+ netclose_txnotify(psock, conn);
#ifdef CONFIG_NET_SOLINGER
/* Wait only if we are lingering */
diff --git a/nuttx/net/socket/net_sendfile.c b/nuttx/net/socket/net_sendfile.c
index 5274eb4ed..df72cecef 100644
--- a/nuttx/net/socket/net_sendfile.c
+++ b/nuttx/net/socket/net_sendfile.c
@@ -387,6 +387,61 @@ wait:
}
/****************************************************************************
+ * Function: sendfile_txnotify
+ *
+ * Description:
+ * Notify the appropriate device driver that we are have data ready to
+ * be send (TCP)
+ *
+ * Parameters:
+ * psock - Socket state structure
+ * conn - The TCP connection structure
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void sendfile_txnotify(FAR struct socket *psock,
+ FAR struct tcp_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->domain == PF_INET)
+#endif
+ {
+ /* Notify the device driver that send data is available */
+
+#ifdef CONFIG_NET_MULTILINK
+ 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->domain == PF_INET6) */
+#endif /* CONFIG_NET_IPv4 */
+ {
+ /* Notify the device driver that send data is available */
+
+ DEBUGASSERT(psock->domain == PF_INET6);
+#ifdef CONFIG_NET_MULTILINK
+ 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
****************************************************************************/
@@ -564,11 +619,7 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset,
/* Notify the device driver of the availability of TX data */
-#ifdef CONFIG_NET_MULTILINK
- netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
-#else
- netdev_ipv4_txnotify(conn->u.ipv4.raddr);
-#endif
+ sendfile_txnotify(psock, conn);
net_lockedwait(&state.snd_sem);
}
while (state.snd_sent >= 0 && state.snd_acked < state.snd_flen);
diff --git a/nuttx/net/socket/recvfrom.c b/nuttx/net/socket/recvfrom.c
index af633fbb2..4cc8d8275 100644
--- a/nuttx/net/socket/recvfrom.c
+++ b/nuttx/net/socket/recvfrom.c
@@ -1040,6 +1040,83 @@ static ssize_t recvfrom_result(int result, struct recvfrom_s *pstate)
#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */
/****************************************************************************
+ * Function: recvfromo_pkt_rxnotify
+ *
+ * Description:
+ * Notify the appropriate device driver that we are ready to receive a
+ * packet (PKT)
+ *
+ * Parameters:
+ * conn - The PKT connection structure
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+#if 0 /* Not implemented */
+static void recvfromo_pkt_rxnotify(FAR struct pkt_conn_s *conn)
+{
+# warning Missing logic
+}
+#endif
+
+/****************************************************************************
+ * Function: recvfrom_udp_rxnotify
+ *
+ * Description:
+ * Notify the appropriate device driver that we are ready to receive a
+ * packet (UDP)
+ *
+ * Parameters:
+ * psock - Socket state structure
+ * conn - The UDP connection structure
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void recvfrom_udp_rxnotify(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->domain == PF_INET)
+#endif
+ {
+ /* Notify the device driver of the receive ready */
+
+#ifdef CONFIG_NET_MULTILINK
+ netdev_ipv4_rxnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
+#else
+ netdev_ipv4_rxnotify(conn->u.ipv4.raddr);
+#endif
+ }
+#endif /* CONFIG_NET_IPv4 */
+
+#ifdef CONFIG_NET_IPv6
+#ifdef CONFIG_NET_IPv4
+ else /* if (psock->domain == PF_INET6) */
+#endif /* CONFIG_NET_IPv4 */
+ {
+ /* Notify the device driver of the receive ready */
+
+ DEBUGASSERT(psock->domain == PF_INET6);
+#ifdef CONFIG_NET_MULTILINK
+ netdev_ipv6_rxnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
+#else
+ netdev_ipv6_rxnotify(conn->u.ipv6.raddr);
+#endif
+ }
+#endif /* CONFIG_NET_IPv6 */
+}
+
+/****************************************************************************
* Function: pkt_recvfrom
*
* Description:
@@ -1095,12 +1172,8 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Notify the device driver of the receive call */
-#if 0 /* No */
-#ifdef CONFIG_NET_MULTILINK
- netdev_ipv4_rxnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
-#else
- netdev_ipv4_rxnotify(conn->u.ipv4.raddr);
-#endif
+#if 0 /* Not implemented */
+ recvfromo_pkt_rxnotify(conn);
#endif
/* Wait for either the receive to complete or for an error/timeout to occur.
@@ -1195,11 +1268,7 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Notify the device driver of the receive call */
-#ifdef CONFIG_NET_MULTILINK
- netdev_ipv4_rxnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
-#else
- netdev_ipv4_rxnotify(conn->u.ipv4.raddr);
-#endif
+ recvfrom_udp_rxnotify(psock, conn);
/* 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)
diff --git a/nuttx/net/socket/sendto.c b/nuttx/net/socket/sendto.c
index c8e40c2ef..bced1ea82 100644
--- a/nuttx/net/socket/sendto.c
+++ b/nuttx/net/socket/sendto.c
@@ -295,7 +295,62 @@ static uint16_t sendto_interrupt(FAR struct net_driver_s *dev, FAR void *conn,
#endif
/****************************************************************************
- * Global Functions
+ * 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->domain == PF_INET)
+#endif
+ {
+ /* Notify the device driver that send data is available */
+
+#ifdef CONFIG_NET_MULTILINK
+ 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->domain == PF_INET6) */
+#endif /* CONFIG_NET_IPv4 */
+ {
+ /* Notify the device driver that send data is available */
+
+ DEBUGASSERT(psock->domain == PF_INET6);
+#ifdef CONFIG_NET_MULTILINK
+ 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
****************************************************************************/
/****************************************************************************
@@ -492,11 +547,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
/* Notify the device driver of the availability of TX data */
-#ifdef CONFIG_NET_MULTILINK
- netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
-#else
- netdev_ipv4_txnotify(conn->u.ipv4.raddr);
-#endif
+ sendto_txnotify(psock, conn);
/* 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)
diff --git a/nuttx/net/tcp/tcp_send_buffered.c b/nuttx/net/tcp/tcp_send_buffered.c
index 4efae569f..ce71c0e0b 100644
--- a/nuttx/net/tcp/tcp_send_buffered.c
+++ b/nuttx/net/tcp/tcp_send_buffered.c
@@ -726,6 +726,61 @@ static uint16_t psock_send_interrupt(FAR struct net_driver_s *dev,
}
/****************************************************************************
+ * Function: send_txnotify
+ *
+ * Description:
+ * Notify the appropriate device driver that we are have data ready to
+ * be send (TCP)
+ *
+ * Parameters:
+ * psock - Socket state structure
+ * conn - The TCP connection structure
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void send_txnotify(FAR struct socket *psock,
+ FAR struct tcp_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->domain == PF_INET)
+#endif
+ {
+ /* Notify the device driver that send data is available */
+
+#ifdef CONFIG_NET_MULTILINK
+ 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->domain == PF_INET6) */
+#endif /* CONFIG_NET_IPv4 */
+ {
+ /* Notify the device driver that send data is available */
+
+ DEBUGASSERT(psock->domain == PF_INET6);
+#ifdef CONFIG_NET_MULTILINK
+ 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
****************************************************************************/
@@ -887,11 +942,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
/* Notify the device driver of the availability of TX data */
-#ifdef CONFIG_NET_MULTILINK
- netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
-#else
- netdev_ipv4_txnotify(conn->u.ipv4.raddr);
-#endif
+ send_txnotify(psock, conn);
result = len;
}
diff --git a/nuttx/net/tcp/tcp_send_unbuffered.c b/nuttx/net/tcp/tcp_send_unbuffered.c
index decd83a4e..b685838b8 100644
--- a/nuttx/net/tcp/tcp_send_unbuffered.c
+++ b/nuttx/net/tcp/tcp_send_unbuffered.c
@@ -509,6 +509,61 @@ end_wait:
}
/****************************************************************************
+ * Function: send_txnotify
+ *
+ * Description:
+ * Notify the appropriate device driver that we are have data ready to
+ * be send (TCP)
+ *
+ * Parameters:
+ * psock - Socket state structure
+ * conn - The TCP connection structure
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+static inline void send_txnotify(FAR struct socket *psock,
+ FAR struct tcp_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->domain == PF_INET)
+#endif
+ {
+ /* Notify the device driver that send data is available */
+
+#ifdef CONFIG_NET_MULTILINK
+ 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->domain == PF_INET6) */
+#endif /* CONFIG_NET_IPv4 */
+ {
+ /* Notify the device driver that send data is available */
+
+ DEBUGASSERT(psock->domain == PF_INET6);
+#ifdef CONFIG_NET_MULTILINK
+ 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
****************************************************************************/
@@ -658,11 +713,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
/* Notify the device driver of the availability of TX data */
-#ifdef CONFIG_NET_MULTILINK
- netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
-#else
- netdev_ipv4_txnotify(conn->u.ipv4.raddr);
-#endif
+ send_txnotify(psock, conn);
/* Wait for the send to complete or an error to occur: NOTES: (1)
* net_lockedwait will also terminate if a signal is received, (2) interrupts