开发者

How does WSARecv make use of lpOverlapped? How can I manually signal the event?

开发者 https://www.devze.com 2023-03-29 21:32 出处:网络
I need to f开发者_运维技巧igure out how WSARecv uses the lpOverlapped argument when lpCompletionRoutine is null. It signals the event located in lpOverlapped, right? But there must be more to it than

I need to f开发者_运维技巧igure out how WSARecv uses the lpOverlapped argument when lpCompletionRoutine is null. It signals the event located in lpOverlapped, right? But there must be more to it than that.

I'm intercepting normal WSARecv calls so I can log packets, and I can capture the data just fine, but the client hangs and waits to be told that the recv operation is finished. I simply don't know exactly what the real WSARecv function does with lpOverlapped to notify the client that the operation is complete.

When lpOverlapped is passed into WSARecv, lpOverlapped->hEvent is null. So I can't simply do SetEvent() or WSASetEvent(). I can create an event by doing something like lpOverlapped->hEvent = WSACreateEvent() and then set the event, the client still doesn't seem to acknowledge it.

Any help is appreciated.

Thanks!

edit: Example of what I'm doing for my WSARecv call

    int proxyWSARecv(int unused, SOCKET s, LPWSABUF recvBuffer, DWORD bufferCount, LPDWORD bytesRecvd, LPDWORD flags,
    LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine){


    WSAOVERLAPPED wsaoverlapped;
    LPWSAOVERLAPPED ourOverlapped = &wsaoverlapped;
    WSADATA wsaData;
    int rc = WSAStartup(MAKEWORD(2, 2), &wsaData);

    int retnVal;

    __asm{
        push lpCompletionRoutine
        push ourOverlapped // our replacement lpoverlapped
        push flags
        push bytesRecvd
        push bufferCount
        push recvBuffer
        push s
        call p_WSARecv // real WSARecv
        mov retnVal, EAX
    }

    // get overlapped results and log packets here. etc
}


You have to create (and later close) the event manually when setting up the overlapped structure. The event is set by the OS - you only have to wait for it or check it.

If the event of the overlapped structure is NULL, you can still wait for the socket events by using the socket itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号