The WSASend function is used to write outgoing data from one or more buffers on a connection-oriented socket specified by s. It can also be used, however, on connectionless sockets that have a stipulated default peer address established through the connect or WSAConnect function.
For overlapped sockets (created using WSASocket with flag WSA_FLAG_OVERLAPPED) sending information uses overlapped I/O, unless both lpOverlapped and lpCompletionRoutine are NULL. In that case, the socket is treated as a nonoverlapped socket. A completion indication will occur, invoking the completion of a routine or setting of an event object, when the buffer(s) have been consumed by the transport. If the operation does not complete immediately, the final completion status is retrieved through the completion routine or WSAGetOverlappedResult.
If both lpOverlapped and lpCompletionRoutine are NULL, the socket in this function will be treated as a nonoverlapped socket.
For nonoverlapped sockets, the last two parameters (lpOverlapped, lpCompletionRoutine) are ignored and WSASend adopts the same blocking semantics as send. Data is copied from the buffer(s) into the transport's buffer. If the socket is nonblocking and stream oriented, and there is not sufficient space in the transport's buffer, WSASend will return with only part of the application's buffers having been consumed. Given the same buffer situation and a blocking socket, WSASend will block until all of the application's buffer contents have been consumed
The WSASend function provides functionality over and above the standard send function in two important areas:
It can be used in conjunction with overlapped sockets to perform overlapped send operations.
It allows multiple send buffers to be specified making it applicable to the scatter/gather type of I/O.