GetOverlappedResults()根本不返回。
我运行了下面的简单示例,当网络接口中的 IP 地址发生更改时,手动重置事件被设置,我可以看到“IP 地址表已更改..”输出,但即使 bWait 为 false,GetOverlappedResults() 也不会返回. 即使使用 bWait = true 它也应该返回,因为事件已设置,因此 I/O 操作已完成。
到底是怎么回事?
#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
void main()
{
OVERLAPPED overlap;
DWORD ret, nr;
HANDLE hand = NULL;
overlap.hEvent = CreateEvent(NULL, true, false, NULL);
ret = NotifyAddrChange(&hand, &overlap);
for (;;)
{
if ( WaitForSingleObject(overlap.hEvent, INFINITE) == WAIT_OBJECT_0 )
{
printf("IP Address table changed..\n");
ret = GetOverlappedResult(hand, &overlap, &nr, false);
scanf_s("%d %d\n", ret, nr);
printf("done\n");
NotifyAddrChange(&hand, &overlap);
ResetEvent(overlap.hEvent);
}
}
}