Why Cause EINTR ?


 
Thread Tools Search this Thread
Top Forums Programming Why Cause EINTR ?
# 1  
Old 04-01-2003
Why Cause EINTR ?

I write a TCP programe .When I read block at some port I get an EINTR . Why The EINTR caused? How Can I Ingore The EINTR
# 2  
Old 04-01-2003
If a read system call returns a -1 with errno set to EINTR, then it was interrupted by a signal. The default action of every signal is to either be completely ignored or to kill the process. Thus it had to be some signal that was caught.

When you installed your signal handler, I hope that you were using the new Posix sigaction() system call. One of the elements of the sigaction structure is sa_flags. Look at the docs for your OS to see what flags you can set. You probably have one called SA_RESTART. That flag will cause a system call to be restarted, so that if your signal handler returns, the read() will act as if the signal never happened. This is most likely what you want.

Posix does not require support of SA_RESTART, but most OS's do. (And if yours doesn't, I would be interested to learn that.) Without SA_RESTART, you will need to loop back to the read() and restart it yourself.

If you really want to ignore the signal, set sa_handler to SIG_IGN. (If you want to ignore the EINTR, just don't test for that! Smilie )

Be careful that you don't disable too many signals. The remote system could be dead, perhaps forever. The user should be able to abort the program without resorting to "kill -9".
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question