send

Sends bytes though a socket to its connected peer.

Format

#include  <socket.h>

int send  (int s, char *msg, int len, int
          flags);

Arguments

s
A socket descriptor that was created with socket, and connected to another socket using accept or connect.
msg
A pointer to a buffer containing the data to be sent.
len
The length, in bytes, of the data pointed to by msg.
flags
May be either 0 or MSG_OOB. If it is equal to MSG_OOB, the data will be sent out-of-band. This means that the data can be received before other pending data on the receiving socket if the receiver also specifies a MSG_OOB in the flag parameter of the call.

Description

This routine may only be used on connected sockets. To send data on an unconnected socket, use the sendmsg or sendto routines. The send routine passes data along to its connected peer, which may receive the data by using recv.

If there is no space available to buffer the data being sent on the receiving end of the connection, send will normally block until buffer space becomes available. If the socket is defined as nonblocking, however, send will fail with an errno indication of EWOULDBLOCK. If the message is too large to be sent in one piece and the socket type requires that messages be sent atomically (using SOCK_DGRAM), send will fail with an errno indication of EMSGSIZE.

No indication of failure to deliver is implicit in a send. All errors (except EWOULDBLOCK) are detected locally. You may use the select routine to determine when it is possible to send more data.

See also read, recv, recvmsg, recvfrom, getsocketopt, and socket in this appendix.

Return Values
The number of bytes sent. This value will normally equal len
- 1  Indicates an error; errno is set to one of the following:

  • EBADF - The socket descriptor is invalid.

  • ENOTSOCK - The descriptor references a file, not a socket.

  • EFAULT - An invalid user space address was specified for a parameter.

  • EMSGSIZE -The socket requires that messages be sent atomically, and the size of the message to be sent made this impossible.

  • EWOULDBLOCK - Blocks if the system does not have enough space for buffering the user data.
 


Previous Page | Next Page | Table of Contents | Index