From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8ee4430d1820a774 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!out03a.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsinpeer00.lnd.ops.eu.uu.net!emea.uu.net!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: GNAT.Sockets: Timeval_Duration is in milliseconds? Date: Sun, 09 Dec 2007 18:26:16 +0000 Organization: Pushface Message-ID: References: <9d687056-c98b-405a-b166-afddac34f109@e67g2000hsc.googlegroups.com> <99906a58-2645-4880-bd13-9b63a30ffb59@e4g2000hsg.googlegroups.com> NNTP-Posting-Host: pogner.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: news.demon.co.uk 1197224776 3352 62.49.19.209 (9 Dec 2007 18:26:16 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Sun, 9 Dec 2007 18:26:16 +0000 (UTC) Cancel-Lock: sha1:cqkhJM0Uuh1XmlqFg4ZHlNINL1M= User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin) Xref: g2news1.google.com comp.lang.ada:18820 Date: 2007-12-09T18:26:16+00:00 List-Id: gpriv@axonx.com writes: > On Dec 8, 5:11 pm, Simon Wright wrote: >> gp...@axonx.com writes: >> > I find it somewhat misleading that Timeout values use different scale >> > than Ada duration while share that type (not Ada way). Is there a >> > purpose in that (other than direct translation in socket library). It >> > does cost some headache to figure that out and it would be more >> > appropriate in Ada style to make a new type for timeouts or scale it >> > back to seconds. Anyone would agree? >> >> GNAT GPL 2006[1] agrees with you! from GNAT.Sockets, >> >> -- Timeval_Duration is a subtype of Standard.Duration because the full >> -- range of Standard.Duration cannot be represented in the equivalent C >> -- structure. Moreover, negative values are not allowed to avoid system >> -- incompatibilities. >> >> Immediate : constant := 0.0; >> Forever : constant := Duration (Integer'Last) * 1.0; >> >> subtype Timeval_Duration is Duration range Immediate .. Forever; >> >> [1] No GNAT GPL 2007 for Mac OS X :-( > > But that was precisely my point to rather make a new type instead of > subtyping, since scales are totally different. But that is subjective > I guess. Oh. I don't understand why you think that milliseconds are involved at all? *If* a Timeval_Duration was in units of milliseconds you would be completely right. But it is in seconds, just as it should be. If you look at GNAT.Sockets'Body you'll find function To_Timeval (Val : Timeval_Duration) return Timeval is S : time_t; uS : suseconds_t; begin -- If zero, set result as zero (otherwise it gets rounded down to -1) if Val = 0.0 then S := 0; uS := 0; -- Normal case where we do round down else S := time_t (Val - 0.5); uS := suseconds_t (1_000_000 * (Val - Selector_Duration (S))); end if; return (S, uS); end To_Timeval; which is pretty clearly based on *seconds*. (If you wanted to ask what Selector_Duration is doing there -- it's an unconstrained subtype of Timeval_Duration -- you'd have a point!)