Share via


WSPCleanup (Compact 2013)

3/26/2014

This function terminates use of the Windows Sockets service provider.

Syntax

int WSPCleanup(
  LPINT lpErrno 
);

Parameters

  • lpErrno
    [out] Pointer to the error code.

Return Value

The return value is zero if the operation has been successfully initiated. Otherwise, the value SOCKET_ERROR is returned, and a specific error number is available in lpErrno.

The following table shows the possible error codes.

Error value

Description

WSANOTINITIALISED

A successful WSPStartup call must occur before using this function.

WSAENETDOWN

Network subsystem has failed.

WSAEINVAL

Provider identifier given to the name-space provider is not managed by the name-space provider.

Remarks

The Winsock SPI client is required to perform a successful WSPStartup call before it can use Windows Sockets service providers. When it has completed the use of Windows Sockets service providers, the SPI client will call WSPCleanup to deregister itself from a Windows Sockets service provider and allow the service provider to free any resources allocated on behalf of the Winsock client. It is permissible for SPI clients to make more than one WSPStartup call. For each WSPStartup call, a corresponding WSPCleanup call will also be issued. Only the final WSPCleanup for the service provider does the actual cleanup; the preceding calls simply decrement an internal reference count in the Windows Sockets service provider.

When the internal reference count reaches zero and actual cleanup operations commence, any pending blocking or asynchronous calls issued by any thread in this process are canceled without posting any notification messages or signaling any event objects. Any pending overlapped send and receive operations (WSPSend, WSPSendTo, WSPRecv, WSPRecvFrom with an overlapped socket) issued by any thread in this process are also canceled without setting the event object or invoking the completion routine, if specified. In this case, the pending overlapped operations fail with the error status WSA_OPERATION_ABORTED. Any sockets open when WSPCleanup is called are reset and automatically deallocated as if WSPCloseSocket was called; sockets that have been closed with WSPCloseSocket but still have pending data to be sent are not affected - the pending data is still sent.

This function should not return until the service provider DLL is prepared to be unloaded from memory. In particular, any data remaining to be transmitted must either already have been sent or be queued for transmission by portions of the transport stack that will not be unloaded from memory along with the service provider's DLL.

A Windows Sockets service provider must be prepared to deal with a process that terminates without invoking WSPCleanup, for example, as a result of an error. A Windows Sockets service provider must ensure that WSPCleanup leaves things in a state in which the ws2.dll can immediately invoke WSPStartup to reestablish Windows Sockets usage.

Requirements

Header

ws2spi.h

Library

Ws2.lib

See Also

Reference

Winsock SPI Functions
WSPStartup
WSPCloseSocket
WSPShutdown