Send a message to a connected socket
#include <sys/types.h> #include <sys/socket.h> ssize_t send( int s, const void * msg, size_t len, int flags );
- The descriptor for the socket; see socket().
- A pointer to the message that you want to send.
- The length of the message.
- A combination of the following:
- MSG_OOB — process out-of-band data. Use this bit when you send "out-of-band" data on sockets that support this notion (e.g. SOCK_STREAM). The underlying protocol must also support out-of-band data.
- MSG_DONTROUTE — bypass routing; create a direct interface. You normally use this bit only in diagnostic or routing programs.
- MSG_NOSIGNAL — don't raise a SIGPIPE signal when the other end breaks the connection.
Use the -l socket option to qcc to link against this library.
The send(), sendto(), sendmsg(), and sendmmsg() functions are used to transmit a message to another socket. The send() function can be used only when the socket is in a connected state, while sendto(), sendmsg(), and sendmmsg() can be used at any time.
The length of the message is given by len. If the message is too long to pass atomically through the underlying protocol, the error EMSGSIZE is returned, and the message isn't transmitted.
No indication of failure to deliver is implicit in a send(). Locally detected errors are indicated by a return value of -1.
If no message space is available at the socket to hold the message to be transmitted, then send() normally blocks, unless the socket has been placed in nonblocking I/O mode. You can use select() to determine when it's possible to send more data.
The number of bytes sent, or -1 if an error occurs ( errno is set).
- The calling process doesn't have the appropriate privileges.
- The socket's file descriptor is marked O_NONBLOCK, and the requested operation would block.
- An invalid descriptor was specified.
- A connection was forcibly closed by a peer.
- The socket is not connection-mode and no peer address is set.
- An invalid user space address was specified for a parameter.
- A signal interrupted send() before any data was transmitted.
- An I/O error occurred while reading from or writing to the filesystem.
- The socket requires that the message be sent atomically, but the size of the message made this impossible.
- The local network interface used to reach the destination is down.
- No route to the network is present.
- The system couldn't allocate an internal buffer. The operation may succeed when buffers become available.
- The socket isn't connected or otherwise has not had the peer pre-specified.
- The argument s isn't a socket.
- The socket argument is associated with a socket that doesn't support one or more of the values set in flags.
- The socket is shut down for writing, or the socket is connection-mode and is no longer connected. In the latter case, and if the socket is of type SOCK_STREAM, a SIGPIPE signal is generated to the calling thread.
- The socket is marked nonblocking and the requested operation would block.
Last modified: 2014-06-24