SquidTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 21 Time Functions */
10 
11 #ifndef SQUID_TIME_H
12 #define SQUID_TIME_H
13 
14 #include "rfc1123.h"
15 
16 #include <ctime>
17 #include <iosfwd>
18 /* NP: sys/time.h is provided by libcompat */
19 
20 /* Use uint64_t to store milliseconds */
21 typedef uint64_t time_msec_t;
22 
23 /* globals for accessing time */
24 extern struct timeval current_time;
25 extern double current_dtime;
26 extern time_t squid_curtime;
27 
28 time_t getCurrentTime(void);
29 int tvSubMsec(struct timeval, struct timeval);
30 
33 void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
34 
37 void tvAdd(struct timeval &res, struct timeval const &t1, struct timeval const &t2);
38 
41 void tvAssignAdd(struct timeval &t, struct timeval const &add);
42 
44 inline long int tvToMsec(struct timeval &t)
45 {
46  return t.tv_sec * 1000 + t.tv_usec / 1000;
47 }
48 
51 {
52 
53 public:
54  virtual ~TimeEngine();
55 
57  virtual void tick();
58 };
59 
60 // TODO: Remove direct timercmp() calls in legacy code.
61 
62 inline bool
63 operator <(const timeval &a, const timeval &b)
64 {
65  return timercmp(&a, &b, <);
66 }
67 
68 inline bool
69 operator >(const timeval &a, const timeval &b)
70 {
71  return timercmp(&a, &b, >);
72 }
73 
74 inline bool
75 operator !=(const timeval &a, const timeval &b)
76 {
77  return timercmp(&a, &b, !=);
78 }
79 
80 // Operators for timeval below avoid timercmp() because Linux timeradd(3) manual
81 // page says that their timercmp() versions "do not work" on some platforms.
82 
83 inline bool
84 operator <=(const timeval &a, const timeval &b)
85 {
86  return !(a > b);
87 }
88 
89 inline bool
90 operator >=(const timeval &a, const timeval &b)
91 {
92  return !(a < b);
93 }
94 
95 inline bool
96 operator ==(const timeval &a, const timeval &b)
97 {
98  return !(a != b);
99 }
100 
102 std::ostream &operator <<(std::ostream &, const timeval &);
103 
104 namespace Time
105 {
106 
113 const char *FormatStrf(time_t t);
114 
121 const char *FormatHttpd(time_t t);
122 
123 } // namespace Time
124 
125 #endif /* SQUID_TIME_H */
126 
void tvAdd(struct timeval &res, struct timeval const &t1, struct timeval const &t2)
Definition: time.cc:55
bool operator<(const timeval &a, const timeval &b)
Definition: SquidTime.h:63
long int tvToMsec(struct timeval &t)
Convert timeval to milliseconds.
Definition: SquidTime.h:44
bool operator<=(const timeval &a, const timeval &b)
Definition: SquidTime.h:84
bool operator>(const timeval &a, const timeval &b)
Definition: SquidTime.h:69
#define timercmp(tvp, uvp, cmp)
Definition: snmp_api_util.h:76
std::ostream & operator<<(std::ostream &, const timeval &)
prints <seconds>.<microseconds>
Definition: time.cc:85
virtual ~TimeEngine()
Definition: time.cc:75
bool operator>=(const timeval &a, const timeval &b)
Definition: SquidTime.h:90
bool operator==(const timeval &a, const timeval &b)
Definition: SquidTime.h:96
const char * FormatStrf(time_t t)
Definition: time.cc:95
int tvSubMsec(struct timeval, struct timeval)
Definition: time.cc:37
time_t getCurrentTime(void)
Get current time.
void tvAssignAdd(struct timeval &t, struct timeval const &add)
Definition: time.cc:65
struct timeval current_time
Definition: stub_time.cc:15
time_t squid_curtime
Definition: stub_time.cc:17
void tvSub(struct timeval &res, struct timeval const &t1, struct timeval const &t2)
Definition: time.cc:44
const char * FormatHttpd(time_t t)
Definition: time.cc:111
virtual void tick()
Definition: time.cc:79
uint64_t time_msec_t
Definition: SquidTime.h:21
double current_dtime
Definition: stub_time.cc:16
bool operator!=(const timeval &a, const timeval &b)
Definition: SquidTime.h:75

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors