Linux:多SIGIO问题(异步串行通信)
我在我正在处理的 C++ 程序中遇到了与 SIGIO 相关的问题。
- 平台:Linux 2.6.30,x86 架构
- 场景:异步串行通信。
我遵循了Linux串行编程中的这个异步通信示例 HowTo 并且运行完美。
然后我删除了“sleep+check wait_flag”的东西,现在我直接在 signal_handler_IO() 中处理 read() 部分。也就是说,当某些输入可用时,将调用信号处理程序并强制在串行端口 (*) 上进行读取。
我的代码似乎可以工作,但不幸的是,当新输入可用时,SIGIO 信号会多次引发,因此我会得到虚假/不完整的读取(收到的每个 SIGIO 都会强制读取)。
我更改了 VMIN 和 VTIME 串行选项来控制读取缓冲区(即 VMIN= 255/VTIME=15,VMIN=50/VTIME=0,...)。我尝试设置 SA_SIGINFO 标志(正如一些人的建议),但没有成功。
那么:
- 关于 SIGIO 筹集/处理,我缺少什么?
- 有没有办法避免这场“SIGIO风暴”?
- 有什么办法可以控制SIGIO筹集政策吗?
提前致谢。
再见。
(*):实际上我正在关注这个C++ FAQ Lite 提示 因此信号处理程序调用封装了我所有串行处理内容的对象的成员函数。不幸的是,即使我在信号处理程序本身中调用 read() ,问题仍然会发生。
I'm esperiencing a SIGIO-related problem in a C++ program I'm working on.
- Platform: Linux 2.6.30, x86 Arch
- Scenario: async serial communication.
I followed this async-communication example from the Linux Serial Programming HowTo and it worked flawlessy.
Then I removed the "sleep+check wait_flag" thing and now I handle the read() part directly in signal_handler_IO(). That is, when some input is available, the signal handler is called and it forces a read on the serial port (*).
My code seems to work but unfortunately when new input is available the SIGIO signal is raised several times so I get spurious/incomplete reads (each SIGIO received forces a read).
I changed VMIN and VTIME serial options to control the read buffer (i.e. VMIN=255/VTIME=15, VMIN=50/VTIME=0, ...). I tried setting SA_SIGINFO flag (as suggested by some), but no success.
So:
- what am I missing about SIGIO raising/handling?
- is there a way to avoid this "SIGIO storm"?
- is there any way to control SIGIO raising policies?
Thanks in advance.
Bye.
(*): actually I'm following this C++ FAQ Lite hint so the signal handler calls a member function of an object that encapsulates all my serial handling stuff. Unfortunately the problem still happens, even if I invoke read() in the signal handler itself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在信号处理程序中调用
read
吗?这很糟糕。很少有函数是异步信号安全的。 SIGIO风暴可能是由于递归地读取发送SIGIO而引起的。您的信号处理程序应该只设置一个标志并立即返回。You are calling
read
while in a signal handler? This is bad. Very few functions are async-signal safe. The SIGIO storm might be caused by read sending SIGIO recursively. Your signal handler should just set a flag and return immediately.