Date: Tue, 20 Apr 1999 12:09:17 +0200 From: Graham Wheeler <gram@cdsec.com> To: hackers@freebsd.org Subject: Re: Using select() to implement a delay Message-ID: <371C524D.36DBAC17@cdsec.com> References: <199904200945.LAA28715@bowtie.nl>
index | next in thread | previous in thread | raw e-mail
Marc van Kempen wrote:
>
> Graham Wheeler wrote:
>
> > Hi all
> >
> > I have an interesting problem. I have a routine to implement delays:
> >
> > void Sleep(int secs, int usecs = 0)
> > {
> > struct timeval tv;
> > tv.tv_sec = secs;
> > tv.tv_usec = usecs;
> > (void)select(0, 0, 0, 0, &tv);
> > }
> >
> > I am using this both because it gives better resolution than sleep(),
> > and also because it doesn't require the use of SIGALRM, which I am
> > using elsewhere.
> >
> > On my development machine, Sleep(60) does exactly what is expected. On
> > my clients machine, Sleep(60) returns immediately. Both are running
> > FreeBSD 2.2.7. I don't have access to the clients machine, which is
> > in another city, and has no development environment, so I can't run gdb,
> > although it may not give away anything in any case.
> >
> > Does anyone have any ideas why the one works and the other doesn't?
> >
>
> Did you try catching the return value from select, it might be getting a
> signal.
>
I've changed the code to:
void Sleep(int secs, int usecs = 0)
{
struct timeval tv;
tv.tv_sec = secs;
tv.tv_usec = usecs;
if (select(0, 0, 0, 0, &tv)<0)
syslog(LOG_INFO, "Sleep(): select: %m");
}
and have asked the client to run the program. I'll post the results
when I get them back. On the one hand, a signal seems like the only
explanation; on the other, there are no calls to alarm() or other
SIGALRM related routines in the code, and this is also happening with
100% consistency.
--
Dr Graham Wheeler E-mail: gram@cdsec.com
Citadel Data Security Phone: +27(21)423-6065/6/7
Firewalls/Virtual Private Networks Fax: +27(21)24-3656
Internet/Intranet Network Specialists
Data Security Products WWW: http://www.cdsec.com/
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?371C524D.36DBAC17>
