send  1K09.HX

The Windows Sockets send function sends data on a connected socket.

int send (

    SOCKET s,

 

    const char FAR * buf,

 

    int len,

 

    int flags

 

   );

 

 

Parameters

s

[in] A descriptor identifying a connected socket.

buf

[in] A buffer containing the data to be transmitted.

len

[in] The length of the data in buf.

flags

[in] Specifies the way in which the call is made.

 

Remarks

send is used to write outgoing data on a connected socket. For message-oriented sockets, care must be taken not to exceed the maximum packet size of the underlying provider, which can be obtained by getting the value of socket option SO_MAX_MSG_SIZE. If the data is too long to pass atomically through the underlying protocol the error WSAEMSGSIZE is returned, and no data is transmitted.

Note that the successful completion of a send does not indicate that the data was successfully delivered.

If no buffer space is available within the transport system to hold the data to be transmitted, send will block unless the socket has been placed in a nonblocking I/O mode. On nonblocking stream-oriented sockets, the number of bytes written can be between 1 and the requested length, depending on buffer availability on both the local and foreign hosts. The select, WSAAsyncSelect or WSAEventSelect call can be used to determine when it is possible to send more data.

Calling send with a len of zero is to be treated by implementations as successful. In this case, send can return zero as a valid return value. For message-oriented sockets, a zero-length transport datagram is sent.

Flags can be used to influence the behavior of the function invocation beyond the options specified for the associated socket. That is, the semantics of this function are determined by the socket options and the flags parameter. The latter is constructed by or-ing any of the following values:

Value

Meaning

MSG_DONTROUTE

Specifies that the data should not be subject to routing. A Windows Sockets service provider can choose to ignore this flag.

MSG_OOB

Send out-of-band data (stream-style socket such as SOCK_STREAM only. Also see Out-Of-Band dataVFXYGI for a discussion of this topic).

 

Return Values

If no error occurs, send returns the total number of bytes sent. (Note that this can be less than the number indicated by len.) Otherwise, a value of SOCKET_ERROR is returned, and a specific error code can be retrieved by calling WSAGetLastError.

Error Codes

WSANOTINITIALISED

A successful WSAStartup must occur before using this function.

WSAENETDOWN

The network subsystem has failed.

WSAEACCES

The requested address is a broadcast address, but the appropriate flag was not set.

WSAEINTR

The (blocking) call was canceled through WSACancelBlockingCall.

WSAEINPROGRESS

A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.

WSAEFAULT

The buf argument is not totally contained in a valid part of the user address space.

WSAENETRESET

The connection has been broken due to the remote host resetting.

WSAENOBUFS

No buffer space is available.

WSAENOTCONN

The socket is not connected.

WSAENOTSOCK

The descriptor is not a socket.

WSAEOPNOTSUPP

MSG_OOB was specified, but the socket is not stream style such as type SOCK_STREAM, out-of-band data is not supported in the communication domain associated with this socket, or the socket is unidirectional and supports only receive operations.

WSAESHUTDOWN

The socket has been shut down; it is not possible to send on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH.

WSAEWOULDBLOCK

The socket is marked as nonblocking and the requested operation would block.

WSAEMSGSIZE

The socket is message oriented, and the message is larger than the maximum supported by the underlying transport.

WSAEHOSTUNREACH

The remote host cannot be reached from this host at this time.

WSAEINVAL

The socket has not been bound with bind, or an unknown flag was specified, or MSG_OOB was specified for a socket with SO_OOBINLINE enabled.

WSAECONNABORTED

The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable.

WSAECONNRESET

The virtual circuit was reset by the remote side executing a  hard  or  abortive  close. For UPD sockets, the remote host was unable to deliver a previously sent UDP datagram and responded with a "Port Unreachable" ICMP packet. The application should close the socket as it is no longer usable.

WSAETIMEDOUT

The connection has been dropped, because of a network failure or because the system on the other end went down without notice.

 

See Also

recv, recvfrom, select, sendto, socket, WSAAsyncSelect, WSAEventSelect