开发者

Linux: multiple-SIGIO problem (async serial communication)

I'm esperiencing a SIGIO-related problem in a 开发者_JS百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜