WSPEnumNetworkEvents function

The WSPEnumNetworkEvents function reports occurrences of network events for the indicated socket.


int WSPEnumNetworkEvents(
  _In_  SOCKET             s,
  _In_  WSAEVENT           hEventObject,
  _Out_ LPWSANETWORKEVENTS lpNetworkEvents,
  _Out_ LPINT              lpErrno


s [in]

Descriptor identifying the socket.

hEventObject [in]

Optional handle identifying an associated event object to be reset.

lpNetworkEvents [out]

Pointer to a WSANETWORKEVENTS structure that is filled with a record of occurred network events and any associated error codes. The WSANETWORKEVENTS structure is defined in the following text.

lpErrno [out]

Pointer to the error code.

Return value

The return value is zero if the operation was successful. Otherwise, the value SOCKET_ERROR is returned, and a specific error number is available in lpErrno.

Error codeMeaning

The network subsystem has failed.


Indicates that one of the specified parameters was invalid.


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


The descriptor is not a socket.



This function is used to report which network events have occurred for the indicated socket since the last invocation of this function. It is intended for use in conjunction with WSPEventSelect, which associates an event object with one or more network events. Recording of network events commences when WSPEventSelect is called with a nonzero lNetworkEvents parameter and remains in effect until another call is made to WSPEventSelect with the lNetworkEvents parameter set to zero, or until a call is made to WSPAsyncSelect.

WSPEnumNetworkEvents only reports network activity and errors nominated through WSPEventSelect. See the descriptions of WSPSelect and WSPAsyncSelect to find out how those functions report network activity and errors.

The socket's internal record of network events is copied to the structure referenced by lpNetworkEvents, whereafter the internal network events record is cleared. If hEventObject is non-null, the indicated event object is also reset. The Windows Sockets provider guarantees that the operations of copying the network event record, clearing it, and resetting any associated event object are atomic, such that the next occurrence of a nominated network event will cause the event object to become set. In the case of this function returning SOCKET_ERROR, the associated event object is not reset and the record of network events is not cleared.

The WSANETWORKEVENTS structure is defined on the WSANETWORKEVENTS reference page.

The lNetworkEvents member of the WSANETWORKEVENTS structure indicates which of the FD_XXX network events have occurred. The iErrorCode array is used to contain any associated error codes, with array index corresponding to the position of event bits in lNetworkEvents. The identifiers such as FD_READ_BIT and FD_WRITE_BIT can be used to index the iErrorCode array.

Note that only those elements of the iErrorCode array are set that correspond to the bits set in the lNetworkEvents member. Other members are not modified (this is important for backward compatibility with the Windows Socket 2 SPI clients that are not aware of new FD_ROUTING_INTERFACE_CHANGE and FD_ADDRESS_LIST_CHANGE events).

The following error codes can be returned along with the respective network event.


Error codeMeaning
WSAEAFNOSUPPORTAddresses in the specified family cannot be used with this socket.
WSAECONNREFUSEDAn attempt to connect was forcefully rejected.
WSAENETUNREACHThe network cannot be reached from this host at this time.
WSAENOBUFSNo buffer space is available. The socket cannot be connected.
WSAETIMEDOUTAn attempt to connect timed out without establishing a connection.



Error codeMeaning
WSAENETDOWNThe network subsystem has failed.
WSAECONNRESETThe connection was reset by the remote side.
WSAECONNABORTEDThe connection was terminated due to a time-out or other failure.


Event: FD_READ


Event: FD_OOB


Event: FD_QOS




Error codeMeaning
WSAENETUNREACHThe specified destination is no longer reachable.
WSAENETDOWNThe network subsystem has failed.



Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]



See also