Вопрос

My application can simultaneously send and receive data from the client using WSASend and WSARecv. So, How can distinguish which operation was completed in IOCP processing thread (send or receive)?

BOOL bReturn = GetQueuedCompletionStatus(srv.m_hCompPort, &dwBytesTransfered, (LPDWORD)&lpContext, &pOverlapped, INFINITE);

I thought I can use OVERLAPED structure for this purpose, but I can't. Any idea?

Thank You!

Это было полезно?

Решение

Solution is very simple:

struct iOverlaped : public OVERLAPPED{
    enum Type {
        Send,
        Receive
    };
    iOverlaped(Type type_ ) {
        ZeroMemory(this, sizeof(iOverlaped));
        type = type_;
    }

    Type type;
};

And for every connection we have to create two overlapped instances (one per each operation type) ...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top