send

send transmits a message on a connected socket.

Syntax

int send(
    SOCKET s,
    const char *buf,
    int len,
    int flags
);

Parameters

s

Socket descriptor identifying connected socket.

buf

Pointer to a character buffer that holds the data to send.

len

An integer that defines the size in bytes of buf.

flags

A set of flags arguments that is logical OR of one or more of the following:

Flag Description

MSG_DONTROUTE

Send without using routing tables.

MSG_OOB

Process urgent data, SOCK_STREAM only.

 

Return Value

The number of bytes sent if the function succeeds, SOCKET_ERROR if the function fails

Use WSAGetLastError to retrieve a specific error code.

Remarks

If there is insufficient space in the socket send queue to hold all the user data for blocking sockets, the send routines will block the calling process until space becomes available. If the non-blocking TCP socket does not have enough buffer space available to hold the message being sent, the send call does not block, sending as much data it can data sent. If none of the message data fits, then SOCKET_ERROR is returned and WSAEWOULDBLOCK is the last error set.

If the non-blocking UDP socket does not have enough buffer space to fit entire datagram, the send call does not block, SOCKET_ERROR is returned and WSAEWOULDBLOCK is the last error set.

The length of the message is indicated by the len parameter. If the message is too long to pass through the underlying protocol and the protocol does not support fragmentation, SOCKET_ERROR is returned and WSAEMSGSIZE is the last error set.

Successful completion of send does not imply successful reception of the message by the target host, but successful delivery of data to the socket send queue. For most protocols, a return value of SOCKET_ERROR indicates some locally detected error.

Use select function to determine when it is possible to send more data.

Sending UDP Datagrams to a Non-existent Host

When sendto is called with the IP address of the host with no ARP entry, TCP/IP stack sends the ARP request and can send an IP packet only if the ARP reply has been received. The packets intended to be sent to the host are waiting in the socket send queue. If the send socket queue is out of space, sendto will block on a blocking socket and return SOCKET_ERROR with WSAEWOULDBLOCK error code on a non-blocking socket. If ARP reply times out, the waiting packets are discarded.

The space in a send socket queue is controlled by the maximum number of application data bytes and maximum number of datagrams.

The maximum size of socket buffer data bytes is controlled by the socket options SO_SNDBUF for send SO_RCVBUF for recv. The default value for both is 8192.

The maximum size of datagrams is controlled by custom socket options of SOL_SOCKET level SO_SND_DGRAMS for send and SO_RCV_DGRAMS for recv. The default value for both is 1024. SO_SND_DGRAMS and SO_RCV_DGRAMS must be defined in the application as:

#define SO_SND_DGRAMS 0x100B

#define SO_RCV_DGRAMS 0x100C

If blocking behavior is not desirable, an application should not use blocking sockets.

Requirements

Minimum Supported VersionRTX64 2013
HeaderWinsock2.h
LibraryRtTcpip.lib