ここで立ち往生しています、助けてください。C# という名前のパイプ サーバーがあり、パイプは次の方法で作成されます。
new NamedPipeServerStream(pipeName, PipeDirection.InOut, numThreads);
C++ では、次のようにクライアントを作成しました。
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);
パイプ タイプを に設定し、パイプにPIPE_READMODE_BYTE | PIPE_TYPE_BYTE
文字列を書き込む関数 WriteString() を作成しました。関数はおおよそ次のようになります。
// 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);
関数に 2 つの呼び出しを行いました。
WriteString(_T("hello server!")); // message sent and the server saw it correctly
WriteString(_T("goodbye server!")); // message not sent, coz WriteFile() blocked here
問題は次のとおりです。プログラムは、2 回目の WriteString() 呼び出しの最初の WriteFile() 呼び出しでブロックされます。パイプがサーバーによって閉じられている場合にのみ、WriteFile() 呼び出しでエラーが返されます。
これは確実に再現可能です。
ここで WriteFile() 呼び出しをブロックしているのは何ですか? 既に OVERLAPPED ファイル フラグを使用しています。パイプバッファがいっぱい?サーバー側のパイプから読み続けます。
どうもありがとう!