| From: D. Hugh Redelmeier <[email protected]>
| The new libevent code deals with times in milliseconds.
| It would be good if there were a new type to represent these values.
| Currently unsigned long is used (mostly).
Here's a stopgap type to do the job. It has the advantage that almost
no logic changes. It should be a trivial change. It makes the code's
intent clearer. It creates an abstraction.
The disadvantage is that C won't catch any more errors with this.
/* name not well-considered */
/*
* precise_delta_t: delta-time with sub-second precision
*
* - currently milliseconds (this abstraction can be changed)
* - unlike time_t, it cannot be negative or undefined
* - does not have range of time_t so it must be used only
* for near-term events (less than 50 days on a 32-bit machine)
*/
typedef unsigned long precise_delta_t;
#define precise_delta_scale 1000LU /* milliseconds / second */
#define precise_delta_fmt "%lu.03%lus"
#define precise_delta_fmt_args(t) (t) / precise_delta_scale, (t) %
precise_delta_scale
I haven't looked at what conversion functions are needed. They should
check that the range isn't exceeded.
to print one of these values:
printf("value is " precise_delta_fmt "\n",
precise_delta_fmt_args(deadline));
This type should be used for any variable that is to hold one of these
values. That seems pretty simple.
_______________________________________________
Swan-dev mailing list
[email protected]
https://lists.libreswan.org/mailman/listinfo/swan-dev