18,141
社区成员




while(m_hComm)
{
PurgeComm(m_hComm, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
ClearCommError(m_hComm, &dwErrorFlags, &ComStat);
WaitCommEvent( m_hComm, &dwEvtMask,&m_op );
WaitForSingleObject(m_op.hEvent,INFINITE);
dwError = ReadFile(m_hComm,m_rcvbuf,40,&dwRead,&m_op);
}
while(m_hComm)
{
PurgeComm(m_hComm, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
WaitCommEvent( m_hComm, &dwEvtMask,&m_op );
dwRead = GetOverlappedResult(m_hComm,&m_op,&dwTs,TRUE);
//WaitForSingleObject(m_op.hEvent,INFINITE);
ClearCommError(m_hComm, &dwErrorFlags, &ComStat);
if (ComStat.cbInQue>0)
{
dwResult = ReadFile(m_hComm,m_rcvbuf,40,&dwRead,&m_or);
if (!dwResult)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_or.hEvent,INFINITE);
}
}
}
}
把 ReadFile的m_op换成m_or后ReadFile返回成功但是下一次循环还是不阻塞。while(m_hComm)
{
PurgeComm(m_hComm, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
WaitCommEvent( m_hComm, &dwEvtMask,&m_op );
GetOverlappedResult(m_hComm,&m_op,&dwTs,TRUE);
//WaitForSingleObject(m_op.hEvent,INFINITE);
ClearCommError(m_hComm, &dwErrorFlags, &ComStat);
if (ComStat.cbInQue>0)
{
ReadFile(m_hComm,m_rcvbuf,40,&dwRead,&m_op);
}
}
把WaitForSingleObject换成GetOverlappedResult还是这种情况