Gian Paolo Ghilardi
Gian Paolo Ghilardi

Reputation: 1075

Linux: multiple-SIGIO problem (async serial communication)

I'm esperiencing a SIGIO-related problem in a C++ program I'm working on.

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:

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.

Upvotes: 0

Views: 4489

Answers (1)

Tobu
Tobu

Reputation: 25436

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.

Upvotes: 4

Related Questions