* [9fans] Here is a silly question..
@ 2006-11-08 0:00 ISHWAR RATTAN
2006-11-08 0:11 ` Russ Cox
2006-11-08 0:16 ` erik quanstrom
0 siblings, 2 replies; 3+ messages in thread
From: ISHWAR RATTAN @ 2006-11-08 0:00 UTC (permalink / raw)
To: 9fans
How does one do a time-out using alarm() call? It seems
that syscall read() is not aborted by alarm()..
int rd, try = 0;
char buf[1024];
while(try < 2) {
alarm(2 * 1000);
rd = read(0, buf, 1024);
alarm(0);
if(rd > 0) {
write(1, buf, rd);
break;
}
}
-ishwar
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] Here is a silly question..
2006-11-08 0:00 [9fans] Here is a silly question ISHWAR RATTAN
@ 2006-11-08 0:11 ` Russ Cox
2006-11-08 0:16 ` erik quanstrom
1 sibling, 0 replies; 3+ messages in thread
From: Russ Cox @ 2006-11-08 0:11 UTC (permalink / raw)
To: Fans of the OS Plan 9 from Bell Labs
> How does one do a time-out using alarm() call? It seems
> that syscall read() is not aborted by alarm()..
Yes it is.
Russ
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [9fans] Here is a silly question..
2006-11-08 0:00 [9fans] Here is a silly question ISHWAR RATTAN
2006-11-08 0:11 ` Russ Cox
@ 2006-11-08 0:16 ` erik quanstrom
1 sibling, 0 replies; 3+ messages in thread
From: erik quanstrom @ 2006-11-08 0:16 UTC (permalink / raw)
To: 9fans
you need to increment try each time through the loop.
this works for me:
#include <u.h>
#include <libc.h>
void
fu(void)
{
int rd, try;
char buf[1024];
for(try=0; try < 2; try++){
alarm(2 * 1000);
rd = read(0, buf, 1024);
alarm(0);
if(rd > 0) {
write(1, buf, rd);
break;
}
}
}
void
main(void)
{
fu();
exits("");
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-11-08 0:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-08 0:00 [9fans] Here is a silly question ISHWAR RATTAN
2006-11-08 0:11 ` Russ Cox
2006-11-08 0:16 ` erik quanstrom
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).