在不使用 readfile() 的情况下检测 Windows 句柄上的空缓冲区

Posted

技术标签:

【中文标题】在不使用 readfile() 的情况下检测 Windows 句柄上的空缓冲区【英文标题】:Detect empty buffer on a windows handle without using readfile() 【发布时间】:2009-06-02 14:18:55 【问题描述】:

我想知道是否有任何类似 IsBufferEmpty() 的函数可用于同步句柄,而不是使用 ReadFile() 并等待它返回 false。我需要一些东西来消除 ReadFile() 尝试读取数据的延迟。

【问题讨论】:

【参考方案1】:

这是用于串口通信的吗?

如果是这样,你可以使用ClearCommError()函数:

DWORD com_errors = 0;
COMSTAT com_stat;

ClearCommError(serial_port_handle, &com_errors, &com_stat);
/* com_stat.cbInQue now holds the number of characters in the receive buffer */

【讨论】:

用于串口通信。感谢您提供的信息,我从没想到您可以通过明确的错误功能访问它。

以上是关于在不使用 readfile() 的情况下检测 Windows 句柄上的空缓冲区的主要内容,如果未能解决你的问题,请参考以下文章