basil00 / WinDivert

WinDivert: Windows Packet Divert
https://reqrypt.org/windivert.html
Other
2.56k stars 512 forks source link

Non blocking vs blocking #329

Closed prakash-kolandaivelu closed 1 year ago

prakash-kolandaivelu commented 1 year ago

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);
                    }
                }
            }
        }
basil00 commented 1 year ago

_sleep(100);

This is one problem. Use WaitForMultipleObjects with the overlapped structure event instead.