[Discuss] Making read() non-restartable
noel at natnix.com
noel at natnix.com
Tue Dec 5 14:40:01 PST 2006
It is a perl thing. read() is a perl call that does its own buffering.
FOr sockets, you want either recv() or sysread(). Those are the only calls
that will work with select(). If you're trying to do a read-with-timeout,
you may want to consider using select()/recv() instead of SIGALRM.
--Noel
On Tue, Dec 05, 2006 at 02:30:20PM -0800, Peter Scott wrote:
> 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/
>
> _______________________________________________
> Discuss mailing list
> Discuss at vlug.org
> http://ladybug.vlug.org/cgi-bin/mailman/listinfo/discuss
More information about the Discuss
mailing list