Date: Tue, 20 Apr 1999 13:40:35 +0200 From: Graham Wheeler <gram@cdsec.com> To: hackers@freebsd.org Subject: Re: Using select() to implement a delay Message-ID: <371C67B3.1E7CE39A@cdsec.com> References: <3.0.6.32.19990420112535.007d27d0@192.168.255.1>
next in thread | previous in thread | raw e-mail | index | archive | help
Bob Bishop wrote:
>
> Hi,
>
> Most likely your select() is taking a signal; truss might be
It was indeed SIGCHLDs that were causing the problem.
> should in theory be able to write something along the lines of:
>
> do
> r = select(0, 0, 0, 0, &tv);
> while (r == -1 && errno == EINTR);
>
> but AFAIK tv won't get updated correctly, see the BUGS entry in select(2).
I am now using:
void Sleep(int sec_dlay, int usec_dlay)
{
struct timeval tv;
if (sec_dlay > 0)
{
time_t start = time(0);
// We do this in a loop to be signal-resilient
for (;;)
{
tv.tv_sec = sec_dlay - (time(0) - start);
if (tv.tv_sec <= 0) break;
tv.tv_usec = 0;
(void)select(0, 0, 0, 0, &tv);
}
}
if (usec_dlay > 0) // we don't worry about signals for usecs
{
tv.tv_sec = 0;
tv.tv_usec = usec_dlay;
(void)select(0, 0, 0, 0, &tv);
}
}
and all is well.
--
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?371C67B3.1E7CE39A>
