Mailslot polling (asynchronous possible?)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Mailslot polling (asynchronous possible?)

  1. #1
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    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.

  2. #2
    Join Date
    Nov 2003
    Posts
    1,794

    Re: Mailslot polling (asynchronous possible?)

    Don't poll with GetMailslotInfo. Instead, use ReadFile and overlapped I/O.

    gg

  3. #3
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    Re: Mailslot polling (asynchronous possible?)

    Quote Originally Posted by Codeplug View Post
    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.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,352

    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

  5. #5
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    Re: Mailslot polling (asynchronous possible?)

    Quote Originally Posted by VictorN View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center