[Swan-dev] new delta time type

Antony Antony antony at phenome.org
Fri Jan 23 22:59:52 EET 2015


The reason I didn't use timeval immediately in #libevent was due to lack of arithmetic and
configuration option parsing functions. Otherwise timeval seems an obvious choice except when defining constants. 

If we create a type it could be called delta_tv. I guess the configuration parser should understand this and store the value in delta_tv. arithmetic functions and parsing functions looks like a major surgery:) 

If we use timeval, can we use something like http://www.geonius.com/software/libgpl/tv_util.html ;  If the license compatible with libreswan?

A consideration is mixing timeval with existing enum we have, such as secs_per_day, secs_per_minute. I am not sure how to define constants for struct timeval. If that also needs update it could quickly become a lot of work. Float and int  are most friendly to define constants.

One thought that is crossing my mind is why not use a float? We don't want epoch, just delta timeval. So it could fit into float? Then arithmetic and formatting become easier. Still there could be a need for timeval to float and float to timeval conversion functions. 

> microseconds.  (Using "ms" in various names feels a little too specific.)

How do you suggest we format the string? Until now it is only used in debug log

-antony

On Thu, Jan 22, 2015 at 06:59:17PM -0500, D. Hugh Redelmeier wrote:
> The new libevent code deals with times in milliseconds.
> 
> I assume that milliseconds isn't fundamental.  I imagine that the
> actual use is for creating a struct timeval which actually uses
> microseconds.  (Using "ms" in various names feels a little too
> specific.)
> 
> It would be good if there were a new type to represent these values.
> Currently unsigned long is used (mostly).  The C type system can be
> used to catch errors if we help it by using a type that cannot
> accidentally be interpreted as something else.  That's why I changed
> all the other time types into structs (deltatime_t, realtime_t,
> monotime_t).
> 
> An obvious choice would be struct timeval which already exists.
> Doing arithmetic with a struct timeval is a bit awkward but not that
> much arithmetic is being done and it can be encapsulated in functions.
> 
> If we invent our own type for this, what should it be called?  Due to
> lack of imagination, I suggest fine_deltatime_t because it is a delta
> time but with more precision.  But finetime_t is funnier and easier to
> type.  hp_deltatime_t (for High Precision) would be OK.  Better ideas
> are welcome.
> 
> Whatever name we chose, it should be used in renaming
> event_schedule_ms.  If we chose struct timeval, we can just use the
> existing event_schedule_tv.
> _______________________________________________
> Swan-dev mailing list
> Swan-dev at lists.libreswan.org
> https://lists.libreswan.org/mailman/listinfo/swan-dev
> 


More information about the Swan-dev mailing list