Re: non-blocking io, EINTR
- From: "Mark Linn" <mark.linn@xxxxxxxxx>
- Date: Wed, 27 Feb 2008 10:43:13 -0800
On Wed, Feb 27, 2008 at 5:25 AM, James Bailie <jimmy@xxxxxxxxxxxxxxxx> wrote:
Mark Linn wrote:
> I am setting the O_NONBLOCK flag on a socket file descriptor using fcntl,
>
> will a read() on the socket return EINTR when the process get a signal?
By default, read() will restart itself automatically, regardless
of whether the socket is blocking or not, as long as there is
data to be read in the socket receive buffer. You can change
this behavior by calling sigaction(). For example, the code
below will make SIGTERM interrupt system calls. They will return
an error code, usually -1, with the global errno set to EINTR.
If the socket is non-blocking and the socket receive buffer is
empty, then read() will also return an error, but with errno set
to EWOULDBLOCK.
#include <signal.h>
struct sigaction sigact;
sigact.sa_handler = sigterm_handler;
sigemptyset( &sigact.sa_mask );
sigact.sa_flags = 0;
if ( sigaction( SIGTERM, &sigact, NULL ) < 0 )
{
perror( "sigaction()" );
exit( 1 );
}
--
James Bailie <jimmy@xxxxxxxxxxxxxxxx>
http://www.mammothcheese.ca
Thanks, Ed and James,
Then why in the world the sample code in this acm paper would test
EINTR in read and write?
link is here.
http://delivery.acm.org/10.1145/1350000/1344155/9815.html?key1=1344155&key2=2950393021&coll=GUIDE&dl=&CFID=15151515&CFTOKEN=6184618
_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"
- References:
- non-blocking io, EINTR
- From: Mark Linn
- Re: non-blocking io, EINTR
- From: James Bailie
- non-blocking io, EINTR
- Prev by Date: Re: find -lname and -ilname implemented
- Next by Date: Re: find -lname and -ilname implemented
- Previous by thread: Re: non-blocking io, EINTR
- Next by thread: Re: Re: non-blocking io, EINTR
- Index(es):
Relevant Pages
- Interrupted connect(2) and errno issue
... signal, returning EINTR. ... connection establishment will be carried
out asynchronously, ... Further calls to connecton such a socket will return EADDRINUSE,
... (freebsd-arch) - Re: non-blocking io, EINTR
... > will a readon the socket return EINTR when the process get a signal? ...
this behavior by calling sigaction(). ... an error code, usually -1, with the global
errno set to EINTR. ... (freebsd-hackers) - Interrupted system calls on 5.4
... Since moving from 4.11 to 5.4 I have started seeing the occasional write ...
to a socket return with EINTR. ... This puzzles me, as looking at the man
page ... (freebsd-stable) - Re: non-blocking io, EINTR
... will a readon the socket return EINTR when the process get a signal? ...
because that would only happen if the kernel would call ... disables that. ...
(freebsd-hackers) - Re: threading issue : SIGPIPE => SIG_IGN (writing to closed socket)
... In a multithreaded library a thread sets the sigaction SIG_IGN for signal ...
Will EPIPE allways be returned to the same thread if the socket was closed ... the only
way you can guarantee that ... (comp.sys.hp.hpux)