Share via

Winsock Overlapped I/O and Event Objects (Windows CE 5.0)

Send Feedback

Winsock supports overlapped I/O and requires that all transport providers support this capability. Overlapped I/O follows the model established in Win32 and can be performed only on sockets created through the WSASocket function with the WSA_FLAG_OVERLAPPED flag set or with sockets created through the socket function.

Note   Creating a socket with the overlapped attribute has no impact on whether a socket is currently in blocking or nonblocking mode. Sockets created with the overlapped attribute can be used to perform overlapped I/O. Doing so does not change the blocking mode of a socket. Because overlapped I/O operations do not block, the blocking mode of a socket is irrelevant for these operations.

For receiving, applications use the WSARecv or WSARecvFrom functions to supply buffers into which data is to be received. If one or more buffers are posted prior to the time that data has been received by the network, that data could be placed in the user's buffers immediately as the data arrives. By immediately placing the data in the user's buffers and application can avoid the copy operation that would otherwise occur at the time the recv or recvfrom function is invoked. If data is already present when receive buffers are posted, it is copied immediately into the user's buffers.

If data arrives when no receive buffers have been posted by the application, the network resorts to the familiar synchronous style of operation. That is, the incoming data is buffered internally until the application issues a receive call and thereby supplies a buffer into which the data can be copied.

On the sending side, applications use WSASend or WSASendTo to supply pointers to filled buffers and then agree not to disturb the buffers in any way until the network has consumed the buffer's contents.

Overlapped send and receive calls return immediately. A return value of zero indicates that the I/O operation was completed immediately and that the corresponding completion indication already occurred. That is, the associated event object has been signaled, or a completion routine has been queued and will be executed when the calling thread gets into the alertable wait state.

A return value of SOCKET_ERROR coupled with an error code of WSA_IO_PENDING indicates that the overlapped operation has been successfully initiated and that a subsequent indication will be provided when send buffers have been consumed or when a receive operation has been completed. Any other error code indicates that the overlapped operation was not successfully initiated and that no completion indication will be forthcoming.

Both send and receive operations can be overlapped. The receive functions can be invoked several times to post receive buffers in preparation for incoming data, and the send functions can be invoked several times to queue multiple buffers to send. Although the application can rely on a series of overlapped send buffers being sent in the order supplied, the corresponding completion indications might occur in a different order. Likewise, on the receiving side, buffers can be completed in the order they are supplied, but the completion indications might occur in a different order.

Canceling individual overlapped operations pending on a given socket is impossible. However, the closesocket function can be called to close the socket and eventually discontinue all pending operations.

See Also

Winsock Event Objects | Winsock Completion Indications | Overlapped Completion Indication Mechanisms | Extended Byte-Order Conversion Routines | Scatter/Gather I/O Support

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.