我正在尝试为我的命名管道的读取操作设置超时。
为了从命名管道中读取,我正在使用该ReadFile
函数。
我读到可以使用该SetCommTimeouts
功能为此功能设置超时,但是当我尝试使用它时,我收到系统错误 1:“功能不正确”。
这是我的代码(这是客户端):
m_pipe = CreateFileA(pipeName, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file
if (m_pipe != INVALID_HANDLE_VALUE)
{
DWORD mode = PIPE_READMODE_MESSAGE | PIPE_WAIT;
ok = SetNamedPipeHandleState(m_pipe, &mode, NULL, NULL);
COMMTIMEOUTS cto;
cto.ReadTotalTimeoutConstant = 1000;
BOOL time = SetCommTimeouts(m_pipe, &cto);
}
我做错了什么还是该SetCommTimeouts
方法不应该与管道一起使用?有没有其他方法可以获得阅读超时?