gtpc1m4aTransmission Control Protocol/Internet Protocol

send -- Send Data on a Connected Socket

The send function sends packets on the socket with descriptor s. The send function applies to all connected sockets.

Format

#include    <socket.h>
int         send(int s,
                 char *msg,
                 int len
                 int flags);

s
The socket descriptor.

msg
Pointer to the buffer containing the message to transmit.

len
Length of the message pointed to by the msg parameter.

When using TCP/IP offload support:

When using TCP/IP native stack support:

flags
Must be set to 0 or one or more of the following flags. If you specify more than one flag, use the logical OR operator (|) to separate them:

MSG_OOB
Sends out-of-band data on sockets that support it.

MSG_DONTROUTE
The SO_DONTROUTE option is turned on for the duration of the operation.

Normal Return

No indication of failure to deliver is implicit in a send routine. However, if it succeeds, the number of characters sent is returned.

Error Return

A return code equal to -1 indicates an error. You can get the specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.

Note:
Unless otherwise stated in the description, the following error codes can be returned for either TCP/IP offload support or TCP/IP native stack support.

Value
Description

SOCFAULT
Using msg and len results in an attempt to access a protected address space. This error code is returned only for TCP/IP offload support.

SOCINVAL
The value of the len parameter is not valid, the MSG_OOB option was specified for a socket that is not a stream socket, or the MSG_OOB option was specified, but out-of-band data is queued inline for this socket. This error code is returned only for TCP/IP native stack support.

SOCNOBUFS
Buffer space is not available to send the message.

SOCNOTSOCK
The s parameter is not a valid socket descriptor.

SOCWOULDBLOCK
The s parameter is in nonblocking mode and no buffer space is available to hold the message to be sent.

SOCMSGSIZE
The message was too large to be sent. This error code is returned only for TCP/IP native stack support.

SOCNOTCONN
The socket is not connected.

EIBMIUCVERR
An error occurred while the message was sent to the offload device. This error code is returned only for TCP/IP offload support.

E1052STATE
The socket was closed because the system was in or cycling down to 1052 state.

EINACT
All offload devices associated with the socket descriptor have been disconnected. The socket is closed. This error code is returned only for TCP/IP offload support.

EINACTWS
An offload device associated with the socket descriptor has been disconnected. The socket is still available. This error code is returned only for TCP/IP offload support.

ESYSTEMERROR
A system error has occurred and closed the socket.

SOCTIMEDOUT
The operation timed out. The socket is still available. This error code is returned only for TCP/IP native stack support.

Programming Considerations

Examples

The following example sends 256 bytes. No flag is used.

#include <socket.h>

·
·
·
int bytes_sent; int server_sock; char data_sent[256];
·
·
·
bytes_sent = send(server_sock, data_sent, sizeof(data_sent), 0);

The following example sends 64 000 bytes. No flag is used.

#include <socket.h>

·
·
·
#define MESSAGE_SIZE 64000 int bytes_sent; int server_sock; int send_left; int send_rc; char *message_ptr;
·
·
·
message_ptr = malloc (MESSAGE_SIZE); send_left = MESSAGE_SIZE; while (send_left > 0) { send_rc = send(server_sock, message_ptr, send_left, 0); if send_rc == -1 break; send_left -= send_rc; message_ptr += send_rc; } /* End While Loop */

Related Information