Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "timeval.h"
00024
00025 #if defined(WIN32) && !defined(MSDOS)
00026
00027 struct timeval curlx_tvnow(void)
00028 {
00029
00030
00031
00032
00033
00034 struct timeval now;
00035 #if !defined(_WIN32_WINNT) || !defined(_WIN32_WINNT_VISTA) || \
00036 (_WIN32_WINNT < _WIN32_WINNT_VISTA)
00037 DWORD milliseconds = GetTickCount();
00038 now.tv_sec = milliseconds / 1000;
00039 now.tv_usec = (milliseconds % 1000) * 1000;
00040 #else
00041 ULONGLONG milliseconds = GetTickCount64();
00042 now.tv_sec = (long) (milliseconds / 1000);
00043 now.tv_usec = (long) (milliseconds % 1000) * 1000;
00044 #endif
00045
00046 return now;
00047 }
00048
00049 #elif defined(HAVE_CLOCK_GETTIME_MONOTONIC)
00050
00051 struct timeval curlx_tvnow(void)
00052 {
00053
00054
00055
00056
00057
00058
00059
00060 struct timeval now;
00061 struct timespec tsnow;
00062 if(0 == clock_gettime(CLOCK_MONOTONIC, &tsnow)) {
00063 now.tv_sec = tsnow.tv_sec;
00064 now.tv_usec = tsnow.tv_nsec / 1000;
00065 }
00066
00067
00068
00069
00070
00071 #ifdef HAVE_GETTIMEOFDAY
00072 else
00073 (void)gettimeofday(&now, NULL);
00074 #else
00075 else {
00076 now.tv_sec = (long)time(NULL);
00077 now.tv_usec = 0;
00078 }
00079 #endif
00080 return now;
00081 }
00082
00083 #elif defined(HAVE_GETTIMEOFDAY)
00084
00085 struct timeval curlx_tvnow(void)
00086 {
00087
00088
00089
00090
00091
00092 struct timeval now;
00093 (void)gettimeofday(&now, NULL);
00094 return now;
00095 }
00096
00097 #else
00098
00099 struct timeval curlx_tvnow(void)
00100 {
00101
00102
00103
00104 struct timeval now;
00105 now.tv_sec = (long)time(NULL);
00106 now.tv_usec = 0;
00107 return now;
00108 }
00109
00110 #endif
00111
00112
00113
00114
00115
00116
00117
00118
00119 time_t curlx_tvdiff(struct timeval newer, struct timeval older)
00120 {
00121 #if SIZEOF_TIME_T < 8
00122
00123
00124 time_t diff = newer.tv_sec-older.tv_sec;
00125 if(diff >= (0x7fffffff/1000))
00126 return 0x7fffffff;
00127 #endif
00128 return (newer.tv_sec-older.tv_sec)*1000+
00129 (time_t)(newer.tv_usec-older.tv_usec)/1000;
00130 }
00131
00132
00133
00134
00135
00136
00137 double curlx_tvdiff_secs(struct timeval newer, struct timeval older)
00138 {
00139 if(newer.tv_sec != older.tv_sec)
00140 return (double)(newer.tv_sec-older.tv_sec)+
00141 (double)(newer.tv_usec-older.tv_usec)/1000000.0;
00142 else
00143 return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
00144 }
00145
00146
00147 time_t Curl_tvlong(struct timeval t1)
00148 {
00149 return t1.tv_sec;
00150 }