There is any way to avoid polling on Win32 mailslots? I tried to use I/O completion with no results.
My code is structured like the MSDN example, which polls for new messages in a loop using GetMailSlotInfo, which is using too much processor time.
If there is an asynchronous mode of receiving mailslot messages, please help me the proper way to do it.Code:do { DWORD dwNextMsgSize = 0; DWORD dwMsgCount = 0; if (!GetMailslotInfo(g_hMailSlot, 0, &dwNextMsgSize, &dwMsgCount, NULL)) { dprintf(L"GetMailslotInfo FAILED with error %d\n", GetLastError()); rv = GetLastError(); bContinue = FALSE; break; } else { if (dwNextMsgSize) // Messages avail? { while (dwMsgCount != 0) { DWORD dwRead; if (!ReadFile(g_hMailSlot, &ipcMsg, dwNextMsgSize, &dwRead, NULL)) { dprintf(L"ReadFile FAILED with error %d\n",GetLastError()); bContinue = FALSE; rv = GetLastError(); break; } else { // Process mailslot message switch (ipcMsg.msg) { ... } } } } } while(bContinue); dprintf(L"Exiting mailslot thread...\n", rv); return rv; }
Thanks in advance.


Reply With Quote

Bookmarks