comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon.j.wright@mac.com>
Subject: Re: GNAT.Sockets: Timeval_Duration is in milliseconds?
Date: Sun, 09 Dec 2007 18:26:16 +0000
Date: 2007-12-09T18:26:16+00:00	[thread overview]
Message-ID: <m2bq8ziv1z.fsf@mac.com> (raw)
In-Reply-To: 99906a58-2645-4880-bd13-9b63a30ffb59@e4g2000hsg.googlegroups.com

gpriv@axonx.com writes:

> On Dec 8, 5:11 pm, Simon Wright <simon.j.wri...@mac.com> 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!)



  parent reply	other threads:[~2007-12-09 18:26 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-08 19:45 GNAT.Sockets: Timeval_Duration is in milliseconds? gpriv
2007-12-08 22:11 ` Simon Wright
2007-12-08 22:34   ` gpriv
2007-12-09  1:45     ` tmoran
2007-12-09  9:33       ` Dmitry A. Kazakov
2007-12-09 12:50         ` Gautier
2007-12-09 13:37           ` Dmitry A. Kazakov
2007-12-09 14:59             ` Martin Krischik
2007-12-09 17:24               ` Dmitry A. Kazakov
2007-12-09 15:55         ` gpriv
2007-12-09 17:25           ` Dmitry A. Kazakov
2007-12-09 18:26     ` Simon Wright [this message]
2007-12-09 19:36       ` gpriv
2007-12-09 22:51         ` Simon Wright
2007-12-09 23:27           ` gpriv
2007-12-10 20:06             ` Simon Wright
2007-12-10 21:02               ` gpriv
2007-12-11 20:33                 ` Simon Wright
2007-12-13  3:44                   ` gpriv
2007-12-13 13:13                     ` Simon Wright
2007-12-13 14:32                       ` gpriv
2007-12-09 19:46       ` tmoran
2007-12-09  9:01   ` Martin Krischik
2007-12-09  9:32 ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox