简体   繁体   中英

Linux: multiple-SIGIO problem (async serial communication)

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM