[SCM] Samba Shared Repository - branch master updated
Rusty Russell
rusty at samba.org
Wed Jun 1 18:10:48 MDT 2011
On Wed, 1 Jun 2011 11:57:08 +0200, Volker Lendecke <Volker.Lendecke at SerNet.DE> wrote:
> On Wed, Jun 01, 2011 at 11:48:02AM +0200, Rusty Russell wrote:
> > for (i = 0; i < state->request.count; i++) {
> > - end = tevent_timeval_add(&end, 0, state->request.delay);
> > + end = tevent_timeval_add(&end, state->request.delay / 1000000,
> > + state->request.delay % 1000000);
>
> Wouldn't it be smarter to add that knowledge to timeval_add
> than to add the burden to all callers?
>
> Volker
That's what I did for lib/util/time.c by creating explicit
timeval_current_ofs_msec() and timeval_current_ofs_usec() routines. I
think that's clearer. But I didn't want to introduce a new (public)
tevent_ function for this which would have a single user.
I think the real answer is that our timeval handling routines could be
overhauled to always deal pass 'struct timeval' and return them, eg:
struct timeval time_now(void);
struct timeval time_sub(struct timeval recent, struct timeval old);
struct timeval time_add(struct timeval a, struct timeval b);
struct timeval time_divide(struct timeval t, unsigned long div);
struct timeval time_multiply(struct timeval t, unsigned long mult);
uint64_t time_to_msec(struct timeval t);
uint64_t time_to_usec(struct timeval t);
struct timeval time_from_msec(uint64_t msec);
struct timeval time_from_usec(uint64_t usec);
This makes it easier to chain them, and do what this is really trying to do:
now = tevent_timeval_current();
end = now;
for (i = 0; i < state->request.count; i++) {
end = tevent_timeval_add(&end, state->request.delay / 1000000,
state->request.delay % 1000000);
}
if (!tevent_req_set_endtime(req, state->caller.cldap->event.ctx, end)) {
as:
duration = time_multiply(time_usec(state->request.delay),
state->request.count);
if (!tevent_req_set_endtime(req, state->caller.cldap->event.ctx,
time_add(time_current(), duration)))
{
What do you think?
Rusty.
More information about the samba-technical
mailing list