I am stuck here, please help. I have a C# named pipe server, the pipe is created by:
new NamedPipeServerStream(pipeName, PipeDirection.InOut, numThreads);
In C++ I created the client like this:
m_hPipe = CreateFile(
strPipeName, // Pipe name
GENERIC_READ | GENERIC_WRITE, // Read and write access
0, // No sharing
NULL, // Default security attributes
OPEN_EXISTING, // Opens existing pipe
FILE_FLAG_OVERLAPPED,
NULL);
I set the pipe type to PIPE_READMODE_BYTE | PIPE_TYPE_BYTE
I wrote a function WriteString() to write a string to the pipe. The function is roughly like this:
// Write the length of the string to the pipe (using 2 bytes)
bool bResult = WriteFile(m_hPipe, buf, 2, &cbBytesWritten, NULL);
// Write the string itself to the pipe
bResult = WriteFile(m_hPipe, m_chSend, len, &cbBytesWritten, NULL);
// Flush the buffer
FlushFileBuffers(m_hPipe);
I made two calls to the function:
WriteString(_T("hello server!")); // message sent and the server saw it correctly
WriteString(_T("goodbye server!")); // message not sent, coz WriteFile() blocked here
Now the problem is: the program is blocked at the first WriteFile() call in the second WriteString() call. Only when the pipe is closed by the server can the WriteFile() call return with an error.
This is reliably reproducible.
What is blocking the WriteFile() call here? I am already using the OVERLAPPED file flag. Pipe buffer is full? I keep reading from the pipe on the server side.
Thanks a lot!