试图从命名管道中读取。据我所知,客户端连接正常并发送。考虑到代码是从这里的解决方案中获取的,我很难看出我在哪里搞砸了。Readfile 似乎没有得到任何东西。它不回来了。如果在客户端关闭连接,则返回 0。
有任何想法吗?
DWORD WINAPI LogManager::LogCollector(LPVOID args)
{
LogMan *LogMgr = (LogMan*)args;
int run; LogMgr ->GetValue(run);
while (run != LogMan::eNONE) {
HANDLE pipe = CreateNamedPipe("\\\\.\\pipe\\RCLogPipe", PIPE_ACCESS_INBOUND , PIPE_WAIT, 1, 1024, 1024, 120 * 1000, NULL);
ConnectNamedPipe(pipe, NULL);
if (pipe == INVALID_HANDLE_VALUE){
CloseHandle(pipe);
return -1;
}
char line[1024];
DWORD numRead = 0;
if (!ReadFile(pipe, line, 1024, &numRead, NULL) || numRead < 1) return -1;
LogMgr ->Write(line);
LogMgr ->GetValue(run);
CloseHandle(pipe);
}
return 0;
}
客户
var client = new NamedPipeClientStream("RCLogPipe");
client.Connect();
StreamWriter writer = new StreamWriter(client);
if (client.CanWrite) writer.WriteLine("Hello\n");