summaryrefslogtreecommitdiff
path: root/nuttx/net/send.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-06-24 08:03:44 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-06-24 08:03:44 -0600
commit827c7af539993a89f996e29a6836e911f9cc409b (patch)
treee780e089cec0c5bc3eabdf5f94f49b8eb2229366 /nuttx/net/send.c
parent83125b53f24bb60c2076487ca1424af9b0de87da (diff)
downloadpx4-nuttx-827c7af539993a89f996e29a6836e911f9cc409b.tar.gz
px4-nuttx-827c7af539993a89f996e29a6836e911f9cc409b.tar.bz2
px4-nuttx-827c7af539993a89f996e29a6836e911f9cc409b.zip
Separate net/net_send_buffered.c and net/net_send_unbuffered.c to net/tcp/tcp_send_buffered.c, net/tcp/tcp_send_unbuffered.c, and pkt/pkt_send.c
Diffstat (limited to 'nuttx/net/send.c')
-rw-r--r--nuttx/net/send.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/nuttx/net/send.c b/nuttx/net/send.c
index 3efa93b5a..cbec0f7de 100644
--- a/nuttx/net/send.c
+++ b/nuttx/net/send.c
@@ -43,6 +43,8 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include "tcp/tcp.h"
+#include "pkt/pkt.h"
#include "net_internal.h"
/****************************************************************************
@@ -62,6 +64,102 @@
****************************************************************************/
/****************************************************************************
+ * Function: psock_send
+ *
+ * Description:
+ * The send() call may be used only when the socket is in a connected state
+ * (so that the intended recipient is known). The only difference between
+ * send() and write() is the presence of flags. With zero flags parameter,
+ * send() is equivalent to write(). Also, send(sockfd,buf,len,flags) is
+ * equivalent to sendto(sockfd,buf,len,flags,NULL,0).
+ *
+ * Parameters:
+ * psock An instance of the internal socket structure.
+ * buf Data to send
+ * len Length of data to send
+ * flags Send flags
+ *
+ * Returned Value:
+ * On success, returns the number of characters sent. On error,
+ * -1 is returned, and errno is set appropriately:
+ *
+ * EAGAIN or EWOULDBLOCK
+ * The socket is marked non-blocking and the requested operation
+ * would block.
+ * EBADF
+ * An invalid descriptor was specified.
+ * ECONNRESET
+ * Connection reset by peer.
+ * EDESTADDRREQ
+ * The socket is not connection-mode, and no peer address is set.
+ * EFAULT
+ * An invalid user space address was specified for a parameter.
+ * EINTR
+ * A signal occurred before any data was transmitted.
+ * EINVAL
+ * Invalid argument passed.
+ * EISCONN
+ * The connection-mode socket was connected already but a recipient
+ * was specified. (Now either this error is returned, or the recipient
+ * specification is ignored.)
+ * EMSGSIZE
+ * The socket type requires that message be sent atomically, and the
+ * size of the message to be sent made this impossible.
+ * ENOBUFS
+ * The output queue for a network interface was full. This generally
+ * indicates that the interface has stopped sending, but may be
+ * caused by transient congestion.
+ * ENOMEM
+ * No memory available.
+ * ENOTCONN
+ * The socket is not connected, and no target has been given.
+ * ENOTSOCK
+ * The argument s is not a socket.
+ * EOPNOTSUPP
+ * Some bit in the flags argument is inappropriate for the socket
+ * type.
+ * EPIPE
+ * The local end has been shut down on a connection oriented socket.
+ * In this case the process will also receive a SIGPIPE unless
+ * MSG_NOSIGNAL is set.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
+ int flags)
+{
+ int ret;
+
+ switch (psock->s_type)
+ {
+#if defined(CONFIG_NET_PKT)
+ case SOCK_RAW:
+ {
+ ret = pkt_send(psock, buf, len);
+ break;
+ }
+#endif
+
+#if defined(CONFIG_NET_TCP)
+ case SOCK_STREAM:
+ {
+ ret = tcp_send(psock, buf, len);
+ break;
+ }
+#endif
+
+ default:
+ {
+ ret = ERROR;
+ }
+ }
+
+ return ret;
+}
+
+/****************************************************************************
* Function: send
*
* Description: