I want to receive data on named pipe asynchronously. Following is my server code:
bool bContinue = true;
bool bMessageReceived = false;
int iMessage;
DWORD dwBytesRead = 0;
OVERLAPPED oReadOverlapped = {0};
oReadOverlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
while(bContinue)
{
int result = ReadFile(hPipe, &iMessage, sizeof(int), NULL, &oReadOverlapped);
int dwError = GetLastError();
cout<< "readFile Error: " << dwError <<endl;
if( result )
bMessageReceived = true;
else
{
bool ret = GetOverlappedResult(hPipe, &oReadOverlapped, &dwBytesRead,
FALSE);
if( ret )
{
bMessageReceived = true;
}
else
{
dwError = GetLastError();
cout<< "GetOverlappedResult Error: "<<dwError <<endl;
bMessageReceived = !( !ret && dwError == ERROR_IO_INCOMPLETE);
}
}
if( bMessageReceived )
{
ResetEvent(oReadOverlapped.hEvent);
ProcessMessage(iMessage, hPipe);
}
bContinue = !IsServerStopped();
}
Client code send message 'synchronously' with success. But every time server call readFile it returns with ERROR_IO_PENDING and GetOverlappedResult returns with ERROR_IO_INCOMPLETE. It continues in loop. I am using windows vista and Visual Stdio 2010. what could be the problem with this code.
Regards, Khurram.