-
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.
-
January 4th, 2011, 08:22 PM
#2
Re: Mailslot polling (asynchronous possible?)
Don't poll with GetMailslotInfo. Instead, use ReadFile and overlapped I/O.
gg
-
January 4th, 2011, 11:57 PM
#3
Re: Mailslot polling (asynchronous possible?)
Originally Posted by Codeplug
Don't poll with GetMailslotInfo. Instead, use ReadFile and overlapped I/O.
gg
Thank you very much, I didn't know that mailslot handles supported overlapped I/O, I tried to implement it quickly and overlooked that.
-
January 5th, 2011, 04:02 AM
#4
Re: Mailslot polling (asynchronous possible?)
Note that there is a big problem with the mailslots: the most of system administrators just forbid using them.
Victor Nijegorodov
-
January 5th, 2011, 09:44 AM
#5
Re: Mailslot polling (asynchronous possible?)
Originally Posted by VictorN
Note that there is a big problem with the mailslots: the most of system administrators just forbid using them.
I'm going with local IPC only and for a small desktop service, no harm.
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
|