From owner-freebsd-hackers Tue Apr 20 4:43: 8 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from citadel.cdsec.com (citadel.cdsec.com [192.96.22.18]) by hub.freebsd.org (Postfix) with ESMTP id 527BA14CF1 for ; Tue, 20 Apr 1999 04:43:01 -0700 (PDT) (envelope-from gram@cdsec.com) Received: (from nobody@localhost) by citadel.cdsec.com (8.9.3/8.9.3) id NAA26910 for ; Tue, 20 Apr 1999 13:40:33 +0200 (SAST) Received: by citadel via recvmail id 26850; Tue Apr 20 13:40:11 1999 Message-ID: <371C67B3.1E7CE39A@cdsec.com> Date: Tue, 20 Apr 1999 13:40:35 +0200 From: Graham Wheeler X-Mailer: Mozilla 4.08 [en] (X11; I; FreeBSD 2.2.8-RELEASE i386) MIME-Version: 1.0 To: hackers@freebsd.org Subject: Re: Using select() to implement a delay References: <3.0.6.32.19990420112535.007d27d0@192.168.255.1> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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