Windows IO完成端口是否将类用作完成键?

时间:2018-10-10 13:04:13

标签: c++ windows winapi visual-c++ iocp

TLDR -如果我提供一个类对象作为完成键,则GetQueuedCompletionStatus不返回,仅当传递结构对象时才返回。


我使用CreateIoCompletionPort在主线程中创建了IOCP

ShareInfo* l_poShareInfo = new ShareInfo(hDir, p_sSharePath, p_oChangeHandler, dwChangesToMonitor, true);

m_hCompPort = CreateIoCompletionPort(hDir, m_hCompPort, (ULONG_PTR)&l_poShareInfo, 0);

然后我使用GetQueuedCompletionStatus

等待工作线程中的数据
ShareInfo* l_ShareInfo;
GetQueuedCompletionStatus((HANDLE)l_pThis->m_hCompPort, &nBytes, (PULONG_PTR)&l_ShareInfo, &lpOverlapped, INFINITE);

ShareInfo是一个如下类,我将其对象用作完成密钥。

class ShareInfo
{
public:
    ShareInfo();
    ShareInfo(HANDLE p_hDir, const std::wstring & p_sSharePath, FileChangeHandlerBase * p_poChangeHandler, DWORD p_dwChangeFilter, bool p_bWatchSubDir);
    ~ShareInfo();


    OVERLAPPED  m_Overlapped;
    HANDLE      m_hDir;
    TCHAR       m_sSharePath[MAX_PATH];
    CHAR        m_Buffer[4096];
    DWORD       m_dwBufLength;
    DWORD       m_dwChangeFilter;
    FileChangeHandlerBase* m_poChangeHandler;

    BOOL        m_bWatchSubDir;
};

但是,GetQueuedCompletionStatus不返回。如果我提供结构对象而不是类对象,则它将按预期工作。因此,我必须按如下方式转换类,并使用ShareInfo::ShareInfoData对象作为完成密钥。

class ShareInfo
{
public:
    .
    .
    typedef struct 
    {
        OVERLAPPED  m_Overlapped;
        HANDLE      m_hDir;
        TCHAR       m_sSharePath[MAX_PATH];
        CHAR        m_Buffer[4096];
        DWORD       m_dwBufLength;
        DWORD       m_dwChangeFilter;
        FileChangeHandlerBase* m_poChangeHandler;

    }ShareInfoData;

    ShareInfoData   m_shareInfoData;
    BOOL            m_bWatchSubDir;
};

我怀疑完成键不能是类,但是我在官方文档中找不到任何内容。我在这里缺少基本的东西吗?

0 个答案:

没有答案