s3: use monotonic clock for time deltas in smbclient
authorBjörn Jacke <bj@sernet.de>
Mon, 30 Aug 2010 10:15:54 +0000 (12:15 +0200)
committerBjörn Jacke <bj@sernet.de>
Tue, 31 Aug 2010 08:26:04 +0000 (10:26 +0200)
source3/client/client.c

index 0ce446115ffb076a8a31377a03d1de6c7d885a35..c91155991143941870c2c054093d1e078786f8ad 100644 (file)
@@ -1023,7 +1023,7 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
        int handle = 0;
        uint16_t fnum;
        bool newhandle = false;
-       struct timeval tp_start;
+       struct timespec tp_start;
        uint16 attr;
        SMB_OFF_T size;
        off_t start = 0;
@@ -1048,7 +1048,7 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
                return 1;
        }
 
-       GetTimeOfDay(&tp_start);
+       clock_gettime_mono(&tp_start);
 
        status = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE, &fnum);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1115,13 +1115,11 @@ static int do_get(const char *rname, const char *lname_in, bool reget)
        }
 
        {
-               struct timeval tp_end;
+               struct timespec tp_end;
                int this_time;
 
-               GetTimeOfDay(&tp_end);
-               this_time =
-                       (tp_end.tv_sec - tp_start.tv_sec)*1000 +
-                       (tp_end.tv_usec - tp_start.tv_usec)/1000;
+               clock_gettime_mono(&tp_end);
+               this_time = TspecDiff(&tp_start,&tp_end);
                get_total_time_ms += this_time;
                get_total_size += nread;
 
@@ -1681,7 +1679,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
        XFILE *f;
        SMB_OFF_T start = 0;
        int rc = 0;
-       struct timeval tp_start;
+       struct timespec tp_start;
        struct cli_state *targetcli;
        char *targetname = NULL;
        struct push_state state;
@@ -1692,7 +1690,7 @@ static int do_put(const char *rname, const char *lname, bool reput)
                return 1;
        }
 
-       GetTimeOfDay(&tp_start);
+       clock_gettime_mono(&tp_start);
 
        if (reput) {
                status = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE, &fnum);
@@ -1766,13 +1764,11 @@ static int do_put(const char *rname, const char *lname, bool reput)
        }
 
        {
-               struct timeval tp_end;
+               struct timespec tp_end;
                int this_time;
 
-               GetTimeOfDay(&tp_end);
-               this_time =
-                       (tp_end.tv_sec - tp_start.tv_sec)*1000 +
-                       (tp_end.tv_usec - tp_start.tv_usec)/1000;
+               clock_gettime_mono(&tp_end);
+               this_time = TspecDiff(&tp_start,&tp_end);
                put_total_time_ms += this_time;
                put_total_size += state.nread;
 
@@ -4508,9 +4504,11 @@ static void readline_callback(void)
        fd_set fds;
        struct timeval timeout;
        static time_t last_t;
+       struct timespec now;
        time_t t;
 
-       t = time(NULL);
+       clock_gettime_mono(&now);
+       t = now.tv_sec;
 
        if (t - last_t < 5)
                return;