[Discuss] Making read() non-restartable

Peter Scott Peter at PSDT.com
Tue Dec 5 14:30:20 PST 2006


At 12:36 PM 12/5/2006, you wrote:
>Interesting question!  What are you reading from?  A file?  socket?

Socket.

>  How
>do you know that read doesn't get interrupted?

strace.

>  You will only get EINTR
>if read was interrupted before it read anything.  If read() gets n bytes
>before an interrupt, it will return n.
>
>If you're using perl, are you using read() or sysread()?

read().  Now there's an idea... hey, sysread() behaves differently.

Here's read() getting restarted:

alarm(2)                                = 0
rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0
rt_sigaction(SIGALRM, {0x80a4010, [], 0}, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
brk(0x9974000)                          = 0x9974000
read(3, 0x9952388, 4096)                = ? ERESTARTSYS (To be restarted)
--- SIGALRM (Alarm clock) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0
read(3,  <unfinished ...>

And here's sysread() getting interrupted:

alarm(2)                                = 0
rt_sigprocmask(SIG_BLOCK, [ALRM], [], 8) = 0
rt_sigaction(SIGALRM, {0x80a4010, [], 0}, {SIG_DFL}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
read(3, 0x93b9cf0, 42)                  = ? ERESTARTSYS (To be restarted)
--- SIGALRM (Alarm clock) @ 0 (0) ---
sigreturn()                             = ? (mask now [])
rt_sigprocmask(SIG_BLOCK, [ALRM], NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [ALRM], NULL, 8) = 0

Not a heck of a lot of difference.  Maybe it's a perl thing going on.
-- 
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
http://www.perlmedic.com/



More information about the Discuss mailing list