0

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!

Tutankhamen
  • 3,532
  • 1
  • 30
  • 38

1 Answers1

0

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) ...

Tutankhamen
  • 3,532
  • 1
  • 30
  • 38
  • 1
    Actually you have to create one overlapped instance per operation that will be active concurrently. So if you only ever issue your reads from your write completions and your writes from your read completions then you only need one. If you can issue multiple reads and writes at the same time then you need one overlapped structure for each read and write that can be active. The key point is that Overlapped structures are "per operation" data and last for the duration of the operation and must be unique for each active operation. – Len Holgate Aug 15 '13 at 08:25