-
January 4th, 2011, 05:19 PM
#1
Mailslot polling (asynchronous possible?)
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.
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;
}
If there is an asynchronous mode of receiving mailslot messages, please help me the proper way to do it.
Thanks in advance.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|