int asendto(const char *data, size_t len, int flags, const ComboAddress& ip, uint16_t id,
const DNSName& domain, uint16_t qtype, int* fd);
int arecvfrom(std::string& packet, int flags, const ComboAddress& ip, size_t *d_len, uint16_t id,
- const DNSName& domain, uint16_t qtype, int fd, struct timeval* now);
+ const DNSName& domain, uint16_t qtype, int fd, const struct timeval* now);
class LWResException : public PDNSException
{
DTime & operator=(const DTime &dt) = default;
time_t time();
inline void set(); //!< Reset the timer
- inline int udiff(); //!< Return the number of microseconds since the timer was last set.
- inline int udiffNoReset(); //!< Return the number of microseconds since the timer was last set.
+ inline int udiff(bool reset = true); //!< Return the number of microseconds since the timer was last set.
+
+ int udiffNoReset() //!< Return the number of microseconds since the timer was last set.
+ {
+ return udiff(false);
+ }
void setTimeval(const struct timeval& tv)
{
d_set=tv;
gettimeofday(&d_set,0);
}
-inline int DTime::udiff()
-{
- int res=udiffNoReset();
- gettimeofday(&d_set,0);
- return res;
-}
-
-inline int DTime::udiffNoReset()
+inline int DTime::udiff(bool reset)
{
struct timeval now;
-
gettimeofday(&now,0);
+
int ret=1000000*(now.tv_sec-d_set.tv_sec)+(now.tv_usec-d_set.tv_usec);
+
+ if (reset) {
+ d_set = now;
+ }
+
return ret;
}
\return returns -1 in case of error, 0 in case of timeout, 1 in case of an answer
*/
-template<class EventKey, class EventVal>int MTasker<EventKey,EventVal>::waitEvent(EventKey &key, EventVal *val, unsigned int timeoutMsec, struct timeval* now)
+template<class EventKey, class EventVal>int MTasker<EventKey,EventVal>::waitEvent(EventKey &key, EventVal *val, unsigned int timeoutMsec, const struct timeval* now)
{
if(d_waiters.count(key)) { // there was already an exact same waiter
return -1;
\return Returns if there is more work scheduled and recalling schedule now would be useful
*/
-template<class Key, class Val>bool MTasker<Key,Val>::schedule(struct timeval* now)
+template<class Key, class Val>bool MTasker<Key,Val>::schedule(const struct timeval* now)
{
if(!d_runQueue.empty()) {
d_tid=d_runQueue.front();
}
typedef void tfunc_t(void *); //!< type of the pointer that starts a thread
- int waitEvent(EventKey &key, EventVal *val=0, unsigned int timeoutMsec=0, struct timeval* now=0);
+ int waitEvent(EventKey &key, EventVal *val=nullptr, unsigned int timeoutMsec=0, const struct timeval* now=nullptr);
void yield();
- int sendEvent(const EventKey& key, const EventVal* val=0);
+ int sendEvent(const EventKey& key, const EventVal* val=nullptr);
void getEvents(std::vector<EventKey>& events);
void makeThread(tfunc_t *start, void* val);
- bool schedule(struct timeval* now=0);
+ bool schedule(const struct timeval* now=nullptr);
bool noProcesses() const;
unsigned int numProcesses() const;
int getTid() const;
// -1 is error, 0 is timeout, 1 is success
int arecvfrom(std::string& packet, int flags, const ComboAddress& fromaddr, size_t *d_len,
- uint16_t id, const DNSName& domain, uint16_t qtype, int fd, struct timeval* now)
+ uint16_t id, const DNSName& domain, uint16_t qtype, int fd, const struct timeval* now)
{
static optional<unsigned int> nearMissLimit;
if(!nearMissLimit)