Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Win32: WaitCommEvent & GetQueuedCompletionStatus funny...

Options
  • 25-11-2003 12:17pm
    #1
    Registered Users Posts: 79 ✭✭


    Hi all,

    I'm experiencing something odd using WaitCommEvent with IO Completion
    ports - I've looked everywhere for some clues as to what's going on,
    but to no avail, so I'm hoping that some of you may have come across
    something like it. I've got a number of IO Completion port threads,
    and for each IO operation, I've got a class derived from the
    OVERLAPPED structure.

    class Context : public OVERLAPPED
    {
    ...
    public:
    void OnIOComplete(DWORD dwXFerred, DWORD dwErr)
    {
    m_pHandler->OnIOComplete(dwXFerred, dwErr);
    }

    private:
    CIOHandler* m_pHandler;
    }

    For ReadFile, WriteFile and WaitCommEvent operations, I've got a
    separate CIOHandler object, and I set up the Context class with this
    as necessary.

    In the IO Completion port thread, the code looks a little like this:

    DWORD dwXFerred = 0L;
    Context* pContext = NULL;
    ULONG* pCompletion = NULL;


    ...

    if (TRUE == ::GetCompletionStatus(hIOCP, &dwXFerred, &pCompletion,
    (OVERLAPPED**)&pContext, 1000))
    {
    pContext->OnIOComplete(dwXFerred, 0);
    }

    Now... *deep breath* - initially, prior to client connection, I issue
    a WaitCommEvent on the port for the EV_RING event, when this
    happens, a connection script runs, i.e. a series of reads operations,
    making sure that the "RING" and "CONNECT" strings are returned from
    the modem. All is good so far, but then, after the connect is
    received, I issue another WaitCommEvent, waiting for EV_ERR or
    EV_BREAK, and at the same time, issue a ReadFile against the port.
    What seems to be happening, is that in the IO Completion Port thread,
    GetQueuedCompletionStatus is returning TRUE, with the dwXFerred
    parameter set to 4, but there's no data in the port, and the Context
    object returned is the one related to the WaitCommEvent. This
    handler re-issues the WaitCommEvent, as one's supposed to do, and I
    end up in a very busy loop.

    Both SysInternal's PortMon and a line monitor show that no data is in
    the port at all, so I'm wondering what's going on. Any ideas?

    Tendofan


Advertisement