WSAEnumNetworkEvents

15658 단어 NetWork

WSAEnumNetworkEvents function


The WSAEnumNetworkEvents function discovers occurrences of network events for the indicated socket, clear internal network event records, and reset event objects (optional).이 함수는 지정한 플러그인으로 이미 발생한 네트워크 이벤트를 보고 네트워크 이벤트의 기록을 정리한 다음 이벤트 대상을 리셋합니다 (선택 사항).

Syntax


C++
int WSAEnumNetworkEvents(
  _In_   SOCKET s,
  _In_   WSAEVENT hEventObject,
  _Out_  LPWSANETWORKEVENTS lpNetworkEvents
);


Parameters


s [in]
A descriptor identifying the socket.소켓.
hEventObject [in]
An optional handle identifying an associated event object to be reset.리셋되고 싶은 이벤트 핸들, 이 인자는 선택할 수 있습니다.
lpNetworkEvents [out]
A pointer to a WSANETWORKEVENTS structure that is filled with a record of network events that occurred and any associated error codes.WSANET WORKEVENTS 구조체를 가리키는 바늘에 이미 발생한 네트워크 이벤트와 관련된 오류 코드가 채워져 있습니다.

Return value


The return value is zero if the operation was successful. Otherwise, the value SOCKET_ERROR is returned, and a specific error number can be retrieved by calling WSAGetLastError .0이(가) 성공적으로 반환되었습니다.그렇지 않으면 SOCKET_ERROR, WSAGetLastError를 호출하면 구체적인 오류 코드를 얻을 수 있습니다.
Error code
Meaning
WSANOTINITIALISED
A successful WSAStartup call must occur before using this function.초기화되지 않았습니다.
WSAENETDOWN
The network subsystem has failed.네트워크 서브시스템이 실패했습니다.
WSAEINVAL
One of the specified parameters was invalid.매개 변수가 잘못되었습니다.
WSAEINPROGRESS
A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.1.1 버전에 속하는 차단 함수를 호출하거나 서비스 제공자가 여전히 리셋 함수를 처리하고 있습니다.
WSAENOTSOCK
The descriptor is not a socket.비 소켓.
WSAEFAULT
The lpNetworkEvents parameter is not a valid part of the user address space.lpNetwork Events 매개 변수는 사용자의 주소 공간에 없습니다.
 

Remarks


The WSAEnumNetworkEvents function is used to discover which network events have occurred for the indicated socket since the last invocation of this function. It is intended for use in conjunction with WSAEventSelect , which associates an event object with one or more network events. The recording of network events commences whenWSAEventSelect is called with a nonzerolNetworkEvents parameter and remains in effect until another call is made toWSAEventSelect with the lNetworkEvents parameter set to zero, or until a call is made to WSAAsyncSelect .이 함수는 지난번에 이 함수를 호출한 후 연결된 플러그인에서 발생한 네트워크 이벤트를 발견하는 데 사용됩니다.이 함수의 목적은 WSAEventSelect와 함께 사용되며, 후자는 하나의 이벤트 대상을 동일하거나 여러 개의 네트워크 이벤트와 연결시킨다.0이 아닌 lNetwork Events 매개 변수로 WSAEventSelect 함수를 호출하면 네트워크 이벤트를 기록하기 시작하고 다시 0을 매개 변수로 WSAEventSelect를 호출하거나 WSAAsyncSelect를 호출하지 않으면 유효합니다.
WSAEnumNetworkEvents only reports network activity and errors nominated through WSAEventSelect . See the descriptions of select and WSAAsyncSelect to find out how those functions report network activity and errors.이 함수는 WSAEventSelect 함수로 지정된 네트워크 활동 및 오류만 보고합니다.구체적인 매개 변수는 select와 WSAAsyncSelect 함수에 대한 설명을 보십시오.
The socket's internal record of network events is copied to the structure referenced by lpNetworkEvents, after which the internal network events record is cleared. If thehEventObject parameter is not 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.내부 네트워크 이벤트 기록이 삭제되었을 때, 플러그인의 내부 네트워크 이벤트 기록은 lpNetwork Events에 복사됩니다.hEventObject 매개변수가 NULL이 아닌 경우 지정된 이벤트 객체가 재설정됩니다.Windows Sockets 공급자는 네트워크 이벤트 기록을 복사하고 정리하며 관련 이벤트 대상을 리셋하는 것이 원자 작업임을 확인하기 때문에 다음에 발생하는 네트워크 이벤트는 이벤트 대상을 설정합니다.만약 함수가 SOCKET_로 되돌아온다면ERROR, 그러면 관련된 이벤트 대상이 리셋되지 않고 기록도 지워지지 않습니다.
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 the array index corresponding to the position of event bits in lNetworkEvents. 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 lNetworkEvents parameter. Other parameters are not modified (this is important for backward compatibility with the applications that are not aware of new FD_ROUTING_INTERFACE_CHANGE and FD_ADDRESS_LIST_CHANGE events).WSANETWORKEVENTS 구조체의 lNetwork Events 구성원으로 이미 발생한 FD_XXX 이벤트.iErrorCode 배열은 lNetwork Events 비트와 관련된 위치에 대한 오류 코드를 저장하는 데 사용됩니다.FD_와 유사READ 및 FD_WRITE_BIT 식별자는 iErrorCode 배열의 아래 첨자를 나타낼 수 있습니다.iErrorCode 그룹에는 연결된 lNetwork Events의 비트 비트에 설정된 요소만 설정됩니다.(대략적으로 A에 설정된 경우에만 B에 설정됩니다.)
The following error codes can be returned along with the corresponding network event.다음은 관련 네트워크 이벤트가 되돌아오는 오류 코드입니다.
Event: FD_CONNECT
Error code
Meaning
WSAEAFNOSUPPORT
Addresses in the specified family cannot be used with this socket.
WSAECONNREFUSED
The attempt to connect was forcefully rejected.
WSAENETUNREACH
The network cannot be reached from this host at this time.
WSAENOBUFS
No buffer space is available. The socket cannot be connected.
WSAETIMEDOUT
An attempt to connect timed out without establishing a connection
 
Event: FD_CLOSE
Error code
Meaning
WSAENETDOWN
The network subsystem has failed.
WSAECONNRESET
The connection was reset by the remote side.
WSAECONNABORTED
The connection was terminated due to a time-out or other failure.
 
Event: FD_ACCEPT
Event: FD_ADDRESS_LIST_CHANGE
Event: FD_GROUP_QOS
Event: FD_QOS
Event: FD_OOB
Event: FD_READ
Event: FD_WRITE
Error code
Meaning
WSAENETDOWN
The network subsystem has failed.
 
Event: FD_ROUTING_INTERFACE_CHANGE
Error code
Meaning
WSAENETUNREACH
The specified destination is no longer reachable.
WSAENETDOWN
The network subsystem has failed.
 

Example Code


The following example demonstrates the use of the WSAEnumNetworkEvents function.다음 예는 함수의 용법을 보여 준다.
C++
#ifndef UNICODE
#define UNICODE
#endif

#define WIN32_LEAN_AND_MEAN

#include <windows.h>

#include <winsock2.h>
#include <Ws2tcpip.h>
#include <stdio.h>

// Link with ws2_32.lib
#pragma comment(lib, "Ws2_32.lib")

int main()
{
//-------------------------
// Declare and initialize variables
    WSADATA wsaData;
    int iResult;

    SOCKET SocketArray[WSA_MAXIMUM_WAIT_EVENTS], ListenSocket;
    WSAEVENT EventArray[WSA_MAXIMUM_WAIT_EVENTS];
    WSANETWORKEVENTS NetworkEvents;
    sockaddr_in InetAddr;
    DWORD EventTotal = 0;
    DWORD Index;
    DWORD i;
    
    HANDLE NewEvent = NULL; 

    // Initialize Winsock
    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != 0) {
        wprintf(L"WSAStartup failed with error: %d
"
, iResult); return 1; } //------------------------- // Create a listening socket ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ListenSocket == INVALID_SOCKET) { wprintf(L"socket function failed with error: %d
"
, WSAGetLastError() ); return 1; } InetAddr.sin_family = AF_INET; InetAddr.sin_addr.s_addr = htonl(INADDR_ANY); InetAddr.sin_port = htons(27015); //------------------------- // Bind the listening socket iResult = bind(ListenSocket, (SOCKADDR *) & InetAddr, sizeof (InetAddr)); if (iResult != 0) { wprintf(L"bind failed with error: %d
"
, WSAGetLastError() ); return 1; } //------------------------- // Create a new event NewEvent = WSACreateEvent(); if (NewEvent == NULL) { wprintf(L"WSACreateEvent failed with error: %d
"
, GetLastError() ); return 1; } //------------------------- // Associate event types FD_ACCEPT and FD_CLOSE // with the listening socket and NewEvent iResult = WSAEventSelect(ListenSocket, NewEvent, FD_ACCEPT | FD_CLOSE); if (iResult != 0) { wprintf(L"WSAEventSelect failed with error: %d
"
, WSAGetLastError() ); return 1; } //------------------------- // Start listening on the socket iResult = listen(ListenSocket, 10); if (iResult != 0) { wprintf(L"listen failed with error: %d
"
, WSAGetLastError() ); return 1; } //------------------------- // Add the socket and event to the arrays, increment number of events SocketArray[EventTotal] = ListenSocket; EventArray[EventTotal] = NewEvent; EventTotal++; //------------------------- // Wait for network events on all sockets Index = WSAWaitForMultipleEvents(EventTotal, EventArray, FALSE, WSA_INFINITE, FALSE);// API , Index = Index - WSA_WAIT_EVENT_0; //------------------------- // Iterate through all events and enumerate // if the wait does not fail. for (i = Index; i < EventTotal; i++) { Index = WSAWaitForMultipleEvents(1, &EventArray[i], TRUE, 1000, FALSE); if ((Index != WSA_WAIT_FAILED) && (Index != WSA_WAIT_TIMEOUT)) { WSAEnumNetworkEvents(SocketArray[i], EventArray[i], &NetworkEvents); } } //... return 0;

Windows Phone 8: This function is supported for Windows Phone Store apps on Windows Phone 8 and later.
Windows 8.1 and Windows Server 2012 R2: This function is supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later.

Requirements


Minimum supported client
Windows 8.1, Windows Vista [desktop apps only]
Minimum supported server
Windows Server 2003 [desktop apps only]
Minimum supported phone
Windows Phone 8
Header
Winsock2.h
Library
Ws2_32.lib
DLL
Ws2_32.dll

See also


Winsock Reference
Winsock Functions
WSAEventSelect

좋은 웹페이지 즐겨찾기