Non blocking vs blocking
prakash-kolandaivelu opened this issue · comments
When testing for performance between blocking and non blocking, blocking performs way better than non blocking. ie more than 50%
Is the bellow code can be tuned or optimized to improve the performance? It is modified passthru.c for non blocking. Added only the while loop.
while (TRUE)
{
addr_len = batch * sizeof(WINDIVERT_ADDRESS);
memset(&Overlapped, 0, sizeof(Overlapped));
receive = WinDivertRecvEx(handle, packet, packet_len, &recv_len, 0,
addr, &addr_len, &Overlapped);
if (!receive)
{
if (GetLastError() != ERROR_IO_PENDING)
{
fprintf(stderr, "error: failed to receive packet (%d)\n",
GetLastError());
continue;
}
else {
while (TRUE) {
HasOverlappedIoCompleted(&Overlapped);
if (Overlapped.Internal == 0) {
break;
}
else {
printf("\nWaiting to receive the packet\n");
_sleep(100);
}
}
}
}
_sleep(100);
This is one problem. Use WaitForMultipleObjects
with the overlapped structure event instead.