From owner-freebsd-hackers Tue Apr 20 12: 3:12 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from apollo.backplane.com (apollo.backplane.com [209.157.86.2]) by hub.freebsd.org (Postfix) with ESMTP id 6B6B714BCD for ; Tue, 20 Apr 1999 12:03:10 -0700 (PDT) (envelope-from dillon@apollo.backplane.com) Received: (from dillon@localhost) by apollo.backplane.com (8.9.3/8.9.1) id MAA99210; Tue, 20 Apr 1999 12:00:18 -0700 (PDT) (envelope-from dillon) Date: Tue, 20 Apr 1999 12:00:18 -0700 (PDT) From: Matthew Dillon Message-Id: <199904201900.MAA99210@apollo.backplane.com> To: Graham Wheeler Cc: hackers@FreeBSD.ORG Subject: Re: Using select() to implement a delay References: <199904200921.LAA09941@cdsec.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG :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? : :TIA :Dr Graham Wheeler E-mail: gram@cdsec.com Well, select() breaks out when the process gets a signal. I recommend checking select()'s return code & errno. I don't think select() is restartable. What you would have to do is use gettimeofday() and then call select(). Check the return value, and if select() was interrupted call gettimeofday() again to figure out how much time elapsed, fixup the tv structure, and loop up. -Matt Matthew Dillon To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message