简体   繁体   中英

Linux socket programming: read data by SIGIO

I coded a program which is reading and writing to some gpio pins and receiving some data through a socket by using datagram connection. I wanted to try to read data from socket when a SIGIO signal is received. But when I attempted to do that, reading / writing operations on gpio pins started to get failed. Why is it happening?

If I do not activate gpio read/write operations to throw SIGIO signal, I am not supposed to receive SIGIO signal because of read/write operations on gpio pins. Am I wrong? Or do all IO operations start to get directed to my signal handler?

Here is a piece of my code where I activated SIGIO signal for socket.

int fd = socket( AF_INET, SOCK_DGRAM, 0 );
...
struct sigaction sa;
memset( &sa, 0, sizeof(struct sigaction) );
sigemptyset( &sa.sa_mask );
sa.sa_sigaction = SignalHandler;
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sigaction( SIGIO, &sa, NULL );
fcntl( fd, F_SETOWN, getpid() );
fcntl( fd, F_SETSIG, SIGIO );
fcntl( fd, F_SETFL, O_NONBLOCK | O_ASYNC );

Thanks.

Note: Code is very huge and it is written in OOP concept. It does not seem possible to copy all code to here. I just copied code related with my problem here. However, I will create an MCVE and copy here in a moment. Also, I am trying to understand the signal concept of linux. Because it implies that I have a lack of understanding of signal concept or SIGIO behaviour.

SIGIO is one big bucket that can be caused from multiple different sources at the same time.

Using select()/poll() in main loop is a better approach than to rely SIGIO

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