1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

lib/util/time.c: timeval_current_ofs_msec

Several places want "milliseconds from current time", and several were
simply doing "msec * 1000" which can (and does in one place) result in
a usec value over 1 a million.

Using a helper to do this is safer and more readable.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2011-06-01 11:21:15 +09:30
parent 9bd695c83f
commit 56e72337b0
8 changed files with 22 additions and 14 deletions

View File

@ -579,6 +579,15 @@ _PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs)
return timeval_add(&tv, secs, usecs);
}
/**
return a timeval milliseconds into the future
*/
_PUBLIC_ struct timeval timeval_current_ofs_msec(uint32_t msecs)
{
struct timeval tv = timeval_current();
return timeval_add(&tv, msecs / 1000, (msecs % 1000) * 1000);
}
/**
compare two timeval structures.
Return -1 if tv1 < tv2

View File

@ -212,6 +212,11 @@ struct timeval timeval_sum(const struct timeval *tv1,
*/
_PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs);
/**
return a timeval milliseconds into the future
*/
_PUBLIC_ struct timeval timeval_current_ofs_msec(uint32_t msecs);
/**
compare two timeval structures.
Return -1 if tv1 < tv2

View File

@ -340,8 +340,7 @@ struct tevent_req *cli_smb_req_create(TALLOC_CTX *mem_ctx,
state->iov_count = iov_count + 3;
if (cli->timeout) {
endtime = timeval_current_ofs(cli->timeout / 1000,
(cli->timeout % 1000) * 1000);
endtime = timeval_current_ofs_msec(cli->timeout);
if (!tevent_req_set_endtime(result, ev, endtime)) {
tevent_req_nomem(NULL, result);
}

View File

@ -604,8 +604,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) ));
source_name, source_addr,
lp_init_logon_delay()));
when = timeval_current_ofs(0,
lp_init_logon_delay() * 1000);
when = timeval_current_ofs_msec(lp_init_logon_delay());
p->locked = true;
event_add_timed(nmbd_event_context(),
NULL,

View File

@ -202,7 +202,7 @@ static struct tevent_req *rpc_tstream_read_send(TALLOC_CTX *mem_ctx,
return tevent_req_post(req, ev);
}
endtime = timeval_current_ofs(0, transp->timeout * 1000);
endtime = timeval_current_ofs_msec(transp->timeout);
if (!tevent_req_set_endtime(subreq, ev, endtime)) {
goto fail;
}
@ -286,7 +286,7 @@ static struct tevent_req *rpc_tstream_write_send(TALLOC_CTX *mem_ctx,
goto fail;
}
endtime = timeval_current_ofs(0, transp->timeout * 1000);
endtime = timeval_current_ofs_msec(transp->timeout);
if (!tevent_req_set_endtime(subreq, ev, endtime)) {
goto fail;
}
@ -374,7 +374,7 @@ static struct tevent_req *rpc_tstream_trans_send(TALLOC_CTX *mem_ctx,
state->req.iov_base = discard_const_p(void *, data);
state->max_rdata_len = max_rdata_len;
endtime = timeval_current_ofs(0, transp->timeout * 1000);
endtime = timeval_current_ofs_msec(transp->timeout);
subreq = tstream_writev_queue_send(state, ev,
transp->stream,

View File

@ -208,8 +208,7 @@ bool push_blocking_lock_request( struct byte_range_lock *br_lck,
blr->expire_time.tv_sec = 0;
blr->expire_time.tv_usec = 0; /* Never expire. */
} else {
blr->expire_time = timeval_current_ofs(lock_timeout/1000,
(lock_timeout % 1000) * 1000);
blr->expire_time = timeval_current_ofs_msec(lock_timeout);
}
blr->lock_num = lock_num;
blr->smblctx = smblctx;

View File

@ -628,9 +628,7 @@ bool push_blocking_lock_request_smb2( struct byte_range_lock *br_lck,
blr->expire_time.tv_sec = 0;
blr->expire_time.tv_usec = 0; /* Never expire. */
} else {
blr->expire_time = timeval_current_ofs(
lock_timeout/1000,
(lock_timeout % 1000) * 1000);
blr->expire_time = timeval_current_ofs_msec(lock_timeout);
}
blr->lock_num = lock_num;

View File

@ -324,8 +324,7 @@ NTSTATUS pvfs_lock(struct ntvfs_module_context *ntvfs,
pending->req = req;
pending->end_time =
timeval_current_ofs(lck->lockx.in.timeout/1000,
1000*(lck->lockx.in.timeout%1000));
timeval_current_ofs_msec(lck->lockx.in.timeout);
}
if (lck->lockx.in.mode & LOCKING_ANDX_SHARED_LOCK) {