WSACleanup

This function terminates the use of Winsock.dll.

At a Glance

Header file: Winsock.h
Windows CE versions: 1.0 and later

Syntax

int WSACleanup()

Return Values

Zero indicates success. SOCKET_ERROR indicates failure. To get a specific error value, call WSAGetLastError.

In a multithreaded environment, WSACleanup terminates Windows Sockets operations for all threads.

Remarks

This function initiates no action and is provided only for compatibility reasons.

An application or DLL is required to perform a successful WSAStartup call before it can use Windows Sockets services. When it has completed the use of Windows Sockets, the application or DLL must call WSACleanup to deregister itself from a Windows Sockets implementation and allow the implementation to free any resources allocated on behalf of the application or DLL.

Sockets that were open when WSACleanup was called are reset and automatically deallocated as if closesocket were called; sockets that have been closed with closesocket but that still have pending data to be sent can be affected—the pending data can be lost if the Winsock.dll is unloaded from memory as the application exits. To insure that all pending data is sent, an application should use shutdown to close the connection, then wait until the close completes before calling closesocket and WSACleanup. All resources and internal state, such as queued un-posted messages, must be deallocated so as to be available to the next user.

There must be a call to WSACleanup for every successful call to WSAStartup made by a task. Only the final WSACleanup for that task does the actual cleanup; the preceding calls simply decrement an internal reference count in the Winsock.dll.

See Also

WSAStartup