* GNAT.Sockets: Timeval_Duration is in milliseconds? @ 2007-12-08 19:45 gpriv 2007-12-08 22:11 ` Simon Wright 2007-12-09 9:32 ` Dmitry A. Kazakov 0 siblings, 2 replies; 24+ messages in thread From: gpriv @ 2007-12-08 19:45 UTC (permalink / raw) Hello, 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? George ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 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 9:01 ` Martin Krischik 2007-12-09 9:32 ` Dmitry A. Kazakov 1 sibling, 2 replies; 24+ messages in thread From: Simon Wright @ 2007-12-08 22:11 UTC (permalink / raw) gpriv@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 :-( ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-08 22:11 ` Simon Wright @ 2007-12-08 22:34 ` gpriv 2007-12-09 1:45 ` tmoran 2007-12-09 18:26 ` Simon Wright 2007-12-09 9:01 ` Martin Krischik 1 sibling, 2 replies; 24+ messages in thread From: gpriv @ 2007-12-08 22:34 UTC (permalink / raw) 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. ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-08 22:34 ` gpriv @ 2007-12-09 1:45 ` tmoran 2007-12-09 9:33 ` Dmitry A. Kazakov 2007-12-09 18:26 ` Simon Wright 1 sibling, 1 reply; 24+ messages in thread From: tmoran @ 2007-12-09 1:45 UTC (permalink / raw) > 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. The Ada 95 LRM 9.6(7) says "...; a value of type Duration is used to represent the length of an interval of time, expressed in seconds." It would be bad practice to use a value of type Duration to represent, say, the number of gallons of gasoline remaining, and it would be even worse, because even more confusing, to use it to represent a number of milliseconds. >> Forever : constant := Duration (Integer'Last) * 1.0; Is that legal Ada? Something like Forever : constant := Integer'last * 1.0; or Forever : constant Duration := Integer'last * 1.0; or Forever : constant Duration := Duration(Integer'last); would seem preferable. (It should probably use Interfaces.C.Int'Last instead of Integer'Last, and if Interfaces.C.Int is 64 bits that would probably give a compile time warning.) > -- Timeval_Duration is a subtype of Standard.Duration because the full > -- range of Standard.Duration cannot be represented in the equivalent C > -- structure. >... > Forever : constant := Duration (Integer'Last) * 1.0; > > subtype Timeval_Duration is Duration range Immediate .. Forever; If the code is going to multiply by 1000 to convert milliseconds to integers to put into the C structure, then of course it should be Forever : constant Duration := Duration(Integer'last)/1000; ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 1:45 ` tmoran @ 2007-12-09 9:33 ` Dmitry A. Kazakov 2007-12-09 12:50 ` Gautier 2007-12-09 15:55 ` gpriv 0 siblings, 2 replies; 24+ messages in thread From: Dmitry A. Kazakov @ 2007-12-09 9:33 UTC (permalink / raw) On Sat, 08 Dec 2007 19:45:53 -0600, tmoran@acm.org wrote: > The Ada 95 LRM 9.6(7) says > "...; a value of type Duration is used to represent the length of > an interval of time, expressed in seconds." > > It would be bad practice to use a value of type Duration to represent, > say, the number of gallons of gasoline remaining, and it would be even > worse, because even more confusing, to use it to represent a number > of milliseconds. Sorry but this makes no sense. The physical entity being measured is duration T. Gallon is a measure of volume L**3. Clearly T /= L**3. As for seconds, milliseconds, years, centuries etc, all they fall under the category T (duration). They are numbers expressing the *same* physical entity. It is rather instructive to use the same type for them when possible. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 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 15:55 ` gpriv 1 sibling, 1 reply; 24+ messages in thread From: Gautier @ 2007-12-09 12:50 UTC (permalink / raw) Dmitry A. Kazakov wrote: > On Sat, 08 Dec 2007 19:45:53 -0600, tmoran@acm.org wrote: > >> The Ada 95 LRM 9.6(7) says >> "...; a value of type Duration is used to represent the length of >> an interval of time, expressed in seconds." >> >> It would be bad practice to use a value of type Duration to represent, >> say, the number of gallons of gasoline remaining, and it would be even >> worse, because even more confusing, to use it to represent a number >> of milliseconds. > > Sorry but this makes no sense. The physical entity being measured is > duration T. Gallon is a measure of volume L**3. Clearly T /= L**3. I think it Tom's point: it is so absurd that it is less likely to be mixed. > As for seconds, milliseconds, years, centuries etc, all they fall under the > category T (duration). They are numbers expressing the *same* physical > entity. Not exactly: the unit for Duration is a second, not a millisecond. I guess it's why it is not a floating type, but a fixed one. The SI unit for time is the second, not the millisecond; for weight it is the kilogram, not the gram. If parts of your program think that a second is worth 1000.0 with type Duration and others think that it is 1.0, you are in trouble - imagine a delay statement that controls the opening of a door in a space station! HAL, please! ______________________________________________________________ Gautier -- http://www.mysunrise.ch/users/gdm/index.htm Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm NB: For a direct answer, e-mail address on the Web site! ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 12:50 ` Gautier @ 2007-12-09 13:37 ` Dmitry A. Kazakov 2007-12-09 14:59 ` Martin Krischik 0 siblings, 1 reply; 24+ messages in thread From: Dmitry A. Kazakov @ 2007-12-09 13:37 UTC (permalink / raw) On Sun, 09 Dec 2007 13:50:08 +0100, Gautier wrote: > Dmitry A. Kazakov wrote: >> On Sat, 08 Dec 2007 19:45:53 -0600, tmoran@acm.org wrote: >> >>> The Ada 95 LRM 9.6(7) says >>> "...; a value of type Duration is used to represent the length of >>> an interval of time, expressed in seconds." >>> >>> It would be bad practice to use a value of type Duration to represent, >>> say, the number of gallons of gasoline remaining, and it would be even >>> worse, because even more confusing, to use it to represent a number >>> of milliseconds. >> >> Sorry but this makes no sense. The physical entity being measured is >> duration T. Gallon is a measure of volume L**3. Clearly T /= L**3. > > I think it Tom's point: it is so absurd that it is less likely to be mixed. But seconds and millisecond can be freely mixed. 1ms + 1s = 1.001s = 1001ms. >> As for seconds, milliseconds, years, centuries etc, all they fall under the >> category T (duration). They are numbers expressing the *same* physical >> entity. > > Not exactly: the unit for Duration is a second, not a millisecond. The point is that the thing measured is duration, not seconds or milliseconds. > I guess it's why it is not a floating type, but a fixed one. ? I never heard that duration were a subject of quantization. In any case it would be far smaller than 1ms. The choice of numerical model is IMO an implementation issue. > The SI unit for time is the > second, not the millisecond; for weight it is the kilogram, not the gram. If > parts of your program think that a second is worth 1000.0 with type Duration and > others think that it is 1.0, you are in trouble - imagine a delay statement that > controls the opening of a door in a space station! HAL, please! Exactly my point, this is why one should use Ada's type Duration. There cannot be any reason to introduce another duration type other than on implementation grounds. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 13:37 ` Dmitry A. Kazakov @ 2007-12-09 14:59 ` Martin Krischik 2007-12-09 17:24 ` Dmitry A. Kazakov 0 siblings, 1 reply; 24+ messages in thread From: Martin Krischik @ 2007-12-09 14:59 UTC (permalink / raw) Dmitry A. Kazakov wrote: > ? I never heard that duration were a subject of quantization. You have not read enough articles on quantum physics then: http://en.wikipedia.org/wiki/Planck_time > In any case it would be far smaller than 1ms. indeed: 5.4 * 10 ** -44 Martin -- mailto://krischik@users.sourceforge.net Ada programming at: http://ada.krischik.com ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 14:59 ` Martin Krischik @ 2007-12-09 17:24 ` Dmitry A. Kazakov 0 siblings, 0 replies; 24+ messages in thread From: Dmitry A. Kazakov @ 2007-12-09 17:24 UTC (permalink / raw) On Sun, 09 Dec 2007 15:59:45 +0100, Martin Krischik wrote: > Dmitry A. Kazakov wrote: > >> ? I never heard that duration were a subject of quantization. > > You have not read enough articles on quantum physics then: That's for sure! (:-)) > http://en.wikipedia.org/wiki/Planck_time > >> In any case it would be far smaller than 1ms. > > indeed: 5.4 * 10 ** -44 I see, the smallest distance + maximal speed gives a duration quantum. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 9:33 ` Dmitry A. Kazakov 2007-12-09 12:50 ` Gautier @ 2007-12-09 15:55 ` gpriv 2007-12-09 17:25 ` Dmitry A. Kazakov 1 sibling, 1 reply; 24+ messages in thread From: gpriv @ 2007-12-09 15:55 UTC (permalink / raw) On Dec 9, 4:33 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de> wrote: > On Sat, 08 Dec 2007 19:45:53 -0600, tmo...@acm.org wrote: > > The Ada 95 LRM 9.6(7) says > > "...; a value of type Duration is used to represent the length of > > an interval of time, expressed in seconds." > > > It would be bad practice to use a value of type Duration to represent, > > say, the number of gallons of gasoline remaining, and it would be even > > worse, because even more confusing, to use it to represent a number > > of milliseconds. > > Sorry but this makes no sense. The physical entity being measured is > duration T. Gallon is a measure of volume L**3. Clearly T /= L**3. As for > seconds, milliseconds, years, centuries etc, all they fall under the > category T (duration). They are numbers expressing the *same* physical > entity. It is rather instructive to use the same type for them when > possible. > > -- > Regards, > Dmitry A. Kazakovhttp://www.dmitry-kazakov.de Conceptually you're right, but many annoying bugs are introduced by assuming wrong scale when using same entities (feet/meter, T(K)/t(C), X/Y/Z coordinates, etc.) In order to make the language work for you one should go with different types. My favorite is X,Y,Z coordinates: all measure distance but misinterpreting those may case a trouble. So by introducing the new types for each plus one direction-less Distance type will be good safety measure while all three are distance entities. Regards, George Privalov. ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 15:55 ` gpriv @ 2007-12-09 17:25 ` Dmitry A. Kazakov 0 siblings, 0 replies; 24+ messages in thread From: Dmitry A. Kazakov @ 2007-12-09 17:25 UTC (permalink / raw) On Sun, 9 Dec 2007 07:55:02 -0800 (PST), gpriv@axonx.com wrote: > On Dec 9, 4:33 am, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de> > wrote: >> On Sat, 08 Dec 2007 19:45:53 -0600, tmo...@acm.org wrote: >>> The Ada 95 LRM 9.6(7) says >>> "...; a value of type Duration is used to represent the length of >>> an interval of time, expressed in seconds." >> >>> It would be bad practice to use a value of type Duration to represent, >>> say, the number of gallons of gasoline remaining, and it would be even >>> worse, because even more confusing, to use it to represent a number >>> of milliseconds. >> >> Sorry but this makes no sense. The physical entity being measured is >> duration T. Gallon is a measure of volume L**3. Clearly T /= L**3. As for >> seconds, milliseconds, years, centuries etc, all they fall under the >> category T (duration). They are numbers expressing the *same* physical >> entity. It is rather instructive to use the same type for them when >> possible. > > Conceptually you're right, but many annoying bugs are introduced by > assuming wrong scale when using same entities (feet/meter, T(K)/t(C), > X/Y/Z coordinates, etc.) In order to make the language work for you > one should go with different types. My favorite is X,Y,Z coordinates: > all measure distance but misinterpreting those may case a trouble. So > by introducing the new types for each plus one direction-less Distance > type will be good safety measure while all three are distance > entities. It makes a lot of sense to use distinct types for horizontal and vertical distances as long no rotation operation is used. I do it too. Similarly it makes even more sense to distinguish screen coordinates and ones relative to some window. The same could be true for durations when applied to different, unsynchronized epochs, for instance. But all this just does not apply to the case at hand. Because that deals with exactly the same physical entity as the delay statement does. Therefore using a separate type is just a bad design that slavishly follows OS APIs. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-08 22:34 ` gpriv 2007-12-09 1:45 ` tmoran @ 2007-12-09 18:26 ` Simon Wright 2007-12-09 19:36 ` gpriv 2007-12-09 19:46 ` tmoran 1 sibling, 2 replies; 24+ messages in thread From: Simon Wright @ 2007-12-09 18:26 UTC (permalink / raw) 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!) ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 18:26 ` Simon Wright @ 2007-12-09 19:36 ` gpriv 2007-12-09 22:51 ` Simon Wright 2007-12-09 19:46 ` tmoran 1 sibling, 1 reply; 24+ messages in thread From: gpriv @ 2007-12-09 19:36 UTC (permalink / raw) On Dec 9, 1:26 pm, Simon Wright <simon.j.wri...@mac.com> wrote: > gp...@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!) That's very good point, but unfortunately it is not what happening in real (windows at least). Setsockoption defines timeouts in milliseconds: http://msdn2.microsoft.com/en-us/library/ms740532.aspx "Sets a timeout, in milliseconds, for blocking receive calls. The default for this option is zero, which indicates that a receive operation will not time out. If a blocking receive call times out, the connection is in an indeterminate state and should be closed." Here is a fragment from my old code to set the timeout in milliseconds and it worked: void Socket::RecvTimeout(int to) { int rc = setsockopt(mSock, SOL_SOCKET, SO_RCVTIMEO, (char*) &to, sizeof(to)); if (rc == SOCKET_ERROR) std::cerr << "Failed socket option" << std::endl; } The confusion comes from crudeness of setsockopt with const char* being passed as parameter. So in Gnat.socket case it is passing structure with second.micosecondsecond part. In windows it may be simply taking the first value and interpret it as milliseconds. Haven checked on Linux yet. What a mess! George ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 19:36 ` gpriv @ 2007-12-09 22:51 ` Simon Wright 2007-12-09 23:27 ` gpriv 0 siblings, 1 reply; 24+ messages in thread From: Simon Wright @ 2007-12-09 22:51 UTC (permalink / raw) gpriv@axonx.com writes: > http://msdn2.microsoft.com/en-us/library/ms740532.aspx > > "Sets a timeout, in milliseconds, for blocking receive calls. The > default for this option is zero, which indicates that a receive > operation will not time out. If a blocking receive call times out, > the connection is in an indeterminate state and should be closed." So if you are using Windows, Microsoft's decision to screw things up by using a different socket argument structure from the pre-existing BSD argument structure means that the current GNAT code indeed works in milliseconds instead of the seconds it is trying to. I suppose we have to report this as a bug in GNAT though it would be much more satisfactory to have Microsoft fix it where it should be fixed. It could never have been the intention to have the effect you observe! Which version of GNAT are you using? Personally I've never used timeouts -- I've used select() and waited 'forever'. ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 22:51 ` Simon Wright @ 2007-12-09 23:27 ` gpriv 2007-12-10 20:06 ` Simon Wright 0 siblings, 1 reply; 24+ messages in thread From: gpriv @ 2007-12-09 23:27 UTC (permalink / raw) On Dec 9, 5:51 pm, Simon Wright <simon.j.wri...@mac.com> wrote: > gp...@axonx.com writes: > >http://msdn2.microsoft.com/en-us/library/ms740532.aspx > > > "Sets a timeout, in milliseconds, for blocking receive calls. The > > default for this option is zero, which indicates that a receive > > operation will not time out. If a blocking receive call times out, > > the connection is in an indeterminate state and should be closed." > > So if you are using Windows, Microsoft's decision to screw things up > by using a different socket argument structure from the pre-existing > BSD argument structure means that the current GNAT code indeed works in > milliseconds instead of the seconds it is trying to. > > I suppose we have to report this as a bug in GNAT though it would be > much more satisfactory to have Microsoft fix it where it should be > fixed. It could never have been the intention to have the effect you > observe! > > Which version of GNAT are you using? > > Personally I've never used timeouts -- I've used select() and waited > 'forever'. Isn't MS always making things "Better" without us even knowing it :-) I use GPS 4.1.3 (20070913), GNAT GPL 2007 (20070405-41) I prefer sockets with timeouts since the application is monitoring many (1..100) "field" devices and it is written around abstract device interfaces. Sets with only one socket seems to be overcomplication, besides I am not sure that timeouts there are not screwed-up on windows either. Those devices send data at least every second, but may "die" quietly and unexpectedly and that should be detected in short order. Timeout works fine when numbers are right. It may be good idea to fix windows version of GNAT though. Regards, George ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 23:27 ` gpriv @ 2007-12-10 20:06 ` Simon Wright 2007-12-10 21:02 ` gpriv 0 siblings, 1 reply; 24+ messages in thread From: Simon Wright @ 2007-12-10 20:06 UTC (permalink / raw) gpriv@axonx.com writes: > I use GPS 4.1.3 (20070913), GNAT GPL 2007 (20070405-41) > > It may be good idea to fix windows version of GNAT though. GNAT 6.0.1 handles this program properly on Windows XP .. with Ada.Calendar; with Ada.Text_IO; use Ada.Text_IO; with GNAT.Sockets; procedure Socket_Times is Sel : GNAT.Sockets.Selector_Type; R, W : GNAT.Sockets.Socket_Set_Type; Stat : GNAT.Sockets.Selector_Status; Start, Finish : Ada.Calendar.Time; use type Ada.Calendar.Time; begin GNAT.Sockets.Initialize; GNAT.Sockets.Create_Selector (Sel); Put_Line ("starting.."); Start := Ada.Calendar.Clock; GNAT.Sockets.Check_Selector (Sel, R, W, Stat, 5.0); Finish := Ada.Calendar.Clock; Put_Line ("..done with " & Stat'Img & " after " & Duration'Image (Finish - Start)); end Socket_Times; (I don't have the output here, but it printed ..done with EXPIRED after 5.0001 or thereabouts, same as GPL 2006 on Mac OS X). Anyone care to try this on other Windows GNAT compiler releases? ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-10 20:06 ` Simon Wright @ 2007-12-10 21:02 ` gpriv 2007-12-11 20:33 ` Simon Wright 0 siblings, 1 reply; 24+ messages in thread From: gpriv @ 2007-12-10 21:02 UTC (permalink / raw) On Dec 10, 3:06 pm, Simon Wright <simon.j.wri...@mac.com> wrote: > gp...@axonx.com writes: > > I use GPS 4.1.3 (20070913), GNAT GPL 2007 (20070405-41) > > > It may be good idea to fix windows version of GNAT though. > > GNAT 6.0.1 handles this program properly on Windows XP .. > > with Ada.Calendar; > with Ada.Text_IO; use Ada.Text_IO; > with GNAT.Sockets; > procedure Socket_Times is > Sel : GNAT.Sockets.Selector_Type; > R, W : GNAT.Sockets.Socket_Set_Type; > Stat : GNAT.Sockets.Selector_Status; > Start, Finish : Ada.Calendar.Time; > use type Ada.Calendar.Time; > begin > GNAT.Sockets.Initialize; > GNAT.Sockets.Create_Selector (Sel); > Put_Line ("starting.."); > Start := Ada.Calendar.Clock; > GNAT.Sockets.Check_Selector (Sel, R, W, Stat, 5.0); > Finish := Ada.Calendar.Clock; > Put_Line ("..done with " > & Stat'Img > & " after " > & Duration'Image (Finish - Start)); > end Socket_Times; > > (I don't have the output here, but it printed > > ..done with EXPIRED after 5.0001 > > or thereabouts, same as GPL 2006 on Mac OS X). > > Anyone care to try this on other Windows GNAT compiler releases? Yep, it worked: ..done with EXPIRED after 4.999302724 ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-10 21:02 ` gpriv @ 2007-12-11 20:33 ` Simon Wright 2007-12-13 3:44 ` gpriv 0 siblings, 1 reply; 24+ messages in thread From: Simon Wright @ 2007-12-11 20:33 UTC (permalink / raw) gpriv@axonx.com writes: > Yep, it worked: > > ..done with EXPIRED after 4.999302724 So GNAT GPL 2007 handles _this_ call right -- which functionality was it you had the problem with? Do you have a test case? ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-11 20:33 ` Simon Wright @ 2007-12-13 3:44 ` gpriv 2007-12-13 13:13 ` Simon Wright 0 siblings, 1 reply; 24+ messages in thread From: gpriv @ 2007-12-13 3:44 UTC (permalink / raw) On Dec 11, 3:33 pm, Simon Wright <simon.j.wri...@mac.com> wrote: > gp...@axonx.com writes: > > Yep, it worked: > > > ..done with EXPIRED after 4.999302724 > > So GNAT GPL 2007 handles _this_ call right -- which functionality was > it you had the problem with? Do you have a test case? Linux update: Timeout value is in seconds here. So it is only a Windows problem as to be expected. thanx ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-13 3:44 ` gpriv @ 2007-12-13 13:13 ` Simon Wright 2007-12-13 14:32 ` gpriv 0 siblings, 1 reply; 24+ messages in thread From: Simon Wright @ 2007-12-13 13:13 UTC (permalink / raw) gpriv@axonx.com writes: > On Dec 11, 3:33 pm, Simon Wright <simon.j.wri...@mac.com> wrote: >> gp...@axonx.com writes: >> > Yep, it worked: >> >> > ..done with EXPIRED after 4.999302724 >> >> So GNAT GPL 2007 handles _this_ call right -- which functionality was >> it you had the problem with? Do you have a test case? > > > Linux update: > > Timeout value is in seconds here. So it is only a Windows problem as > to be expected. Looking at http://msdn2.microsoft.com/en-us/library/ms740141.aspx it turns out that the Windows version of select(2) uses a struct timeval* -- so not surprising that it behaves as we were expecting. Huh. --S ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-13 13:13 ` Simon Wright @ 2007-12-13 14:32 ` gpriv 0 siblings, 0 replies; 24+ messages in thread From: gpriv @ 2007-12-13 14:32 UTC (permalink / raw) On Dec 13, 8:13 am, Simon Wright <simon.j.wri...@mac.com> wrote: > gp...@axonx.com writes: > > On Dec 11, 3:33 pm, Simon Wright <simon.j.wri...@mac.com> wrote: > >> gp...@axonx.com writes: > >> > Yep, it worked: > > >> > ..done with EXPIRED after 4.999302724 > > >> So GNAT GPL 2007 handles _this_ call right -- which functionality was > >> it you had the problem with? Do you have a test case? > > > Linux update: > > > Timeout value is in seconds here. So it is only a Windows problem as > > to be expected. > > Looking athttp://msdn2.microsoft.com/en-us/library/ms740141.aspxit > turns out that the Windows version of select(2) uses a struct timeval* > -- so not surprising that it behaves as we were expecting. Huh. > > --S Microsoft could fix that problem by checking the size of the parameter passed to setsockopt without breaking all the software already written for winsock. George. ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-09 18:26 ` Simon Wright 2007-12-09 19:36 ` gpriv @ 2007-12-09 19:46 ` tmoran 1 sibling, 0 replies; 24+ messages in thread From: tmoran @ 2007-12-09 19:46 UTC (permalink / raw) > *If* a Timeval_Duration was in units of milliseconds you would be > completely right. But it is in seconds, just as it should be. So regardless of where it occurs in the program, the statement T2 := T1 + Duration'(1.0); will result in T2 being one second later than T1 - it will never make T2 one millisecond later than T1. That's a relief. ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-08 22:11 ` Simon Wright 2007-12-08 22:34 ` gpriv @ 2007-12-09 9:01 ` Martin Krischik 1 sibling, 0 replies; 24+ messages in thread From: Martin Krischik @ 2007-12-09 9:01 UTC (permalink / raw) Simon Wright wrote: > [1] No GNAT GPL 2007 for Mac OS X :-( Why not join The GNU Ada Project [1] create your own? Martin [1] http://gnuada.sf.net -- mailto://krischik@users.sourceforge.net Ada programming at: http://ada.krischik.com ^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: GNAT.Sockets: Timeval_Duration is in milliseconds? 2007-12-08 19:45 GNAT.Sockets: Timeval_Duration is in milliseconds? gpriv 2007-12-08 22:11 ` Simon Wright @ 2007-12-09 9:32 ` Dmitry A. Kazakov 1 sibling, 0 replies; 24+ messages in thread From: Dmitry A. Kazakov @ 2007-12-09 9:32 UTC (permalink / raw) On Sat, 8 Dec 2007 11:45:34 -0800 (PST), gpriv@axonx.com wrote: > 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? I do. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2007-12-13 14:32 UTC | newest] Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox