blocking pipe write
-
I am trying to have a overlapped blocking pipe write so that I can have either data sent signal or a timeout signal... The code I have written is as follows
DWORD dwMode = PIPE_READMODE_MESSAGE | PIPE_WAIT; BOOL bSuccess = ::SetNamedPipeHandleState(m_hPipe, &dwMode, NULL, NULL);
and my pipe write function have codeOVERLAPPED op = {0}; op.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); bSuccess = ::WriteFile(m_hPipe, lpBufferPos, dwToWrite, &dwNumberOfBytesWritten, &op); if(bSuccess) { return TRUE; } else { m_dwLastError = ::GetLastError(); if(m_dwLastError == ERROR_IO_PENDING) { switch(WaitForSingleObject(op.hEvent, m_dwTimeOut)) { case WAIT_OBJECT_0: return TRUE; break; case WAIT_TIMEOUT: m_dwLastError = ::GetLastError(); return FALSE; case WAIT_FAILED: m_dwLastError = ::GetLastError(); return FALSE; break; } } else { return FALSE; } } }
The problem that I am facing is that all my Write to pipe function calls keeps returning with TRUE code and the corresponding first Read call in the child process remains locked at the WaitForSingleObject call and then after some write pipe operation in the parent process Read returns with "More data is available" error. Can anyone direct me what I am doing wrong. -
I am trying to have a overlapped blocking pipe write so that I can have either data sent signal or a timeout signal... The code I have written is as follows
DWORD dwMode = PIPE_READMODE_MESSAGE | PIPE_WAIT; BOOL bSuccess = ::SetNamedPipeHandleState(m_hPipe, &dwMode, NULL, NULL);
and my pipe write function have codeOVERLAPPED op = {0}; op.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); bSuccess = ::WriteFile(m_hPipe, lpBufferPos, dwToWrite, &dwNumberOfBytesWritten, &op); if(bSuccess) { return TRUE; } else { m_dwLastError = ::GetLastError(); if(m_dwLastError == ERROR_IO_PENDING) { switch(WaitForSingleObject(op.hEvent, m_dwTimeOut)) { case WAIT_OBJECT_0: return TRUE; break; case WAIT_TIMEOUT: m_dwLastError = ::GetLastError(); return FALSE; case WAIT_FAILED: m_dwLastError = ::GetLastError(); return FALSE; break; } } else { return FALSE; } } }
The problem that I am facing is that all my Write to pipe function calls keeps returning with TRUE code and the corresponding first Read call in the child process remains locked at the WaitForSingleObject call and then after some write pipe operation in the parent process Read returns with "More data is available" error. Can anyone direct me what I am doing wrong.