TLDR - GetQueuedCompletionStatus
does not return if I provide a class object as the completion key, it returns only if structure object is passed instead.
I created a IOCP in main thread using CreateIoCompletionPort
ShareInfo* l_poShareInfo = new ShareInfo(hDir, p_sSharePath, p_oChangeHandler, dwChangesToMonitor, true);
m_hCompPort = CreateIoCompletionPort(hDir, m_hCompPort, (ULONG_PTR)&l_poShareInfo, 0);
and then I wait for data in a worker thread using GetQueuedCompletionStatus
ShareInfo* l_ShareInfo;
GetQueuedCompletionStatus((HANDLE)l_pThis->m_hCompPort, &nBytes, (PULONG_PTR)&l_ShareInfo, &lpOverlapped, INFINITE);
ShareInfo
is a class as follows, whose object I am using as a completion key.
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;
};
However, GetQueuedCompletionStatus
doesn't return. If I provide a structure object instead of a class object, it works as expected. So I had to transform my class as follows and use an object of ShareInfo::ShareInfoData
as completion key.
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;
};
I suspect Completion keys cannot to be classes, but I don't find anything mentioned in the official docs. Am I missing something fundamental here?