Changeset 597

Show
Ignore:
Timestamp:
03/19/06 20:18:31 (7 years ago)
Author:
ahu
Message:

move timeval arithmetic away from dnsreplay-mindex, make DTime able to save a few gettimeofdays

Location:
trunk/pdns/pdns
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/pdns/pdns/dnsreplay-mindex.cc

    r572 r597  
    6767 
    6868 
    69 void normalizeTV(struct timeval& tv) 
    70 { 
    71   if(tv.tv_usec > 1000000) { 
    72     ++tv.tv_sec; 
    73     tv.tv_usec-=1000000; 
    74   } 
    75   else if(tv.tv_usec < 0) { 
    76     --tv.tv_sec; 
    77     tv.tv_usec+=1000000; 
    78   } 
    79 } 
    80  
    81 const struct timeval operator+(const struct timeval& lhs, const struct timeval& rhs) 
    82 { 
    83   struct timeval ret; 
    84   ret.tv_sec=lhs.tv_sec + rhs.tv_sec; 
    85   ret.tv_usec=lhs.tv_usec + rhs.tv_usec; 
    86   normalizeTV(ret); 
    87   return ret; 
    88 } 
    89  
    90 const struct timeval operator-(const struct timeval& lhs, const struct timeval& rhs) 
    91 { 
    92   struct timeval ret; 
    93   ret.tv_sec=lhs.tv_sec - rhs.tv_sec; 
    94   ret.tv_usec=lhs.tv_usec - rhs.tv_usec; 
    95   normalizeTV(ret); 
    96   return ret; 
    97 } 
    9869 
    9970const struct timeval operator*(int fact, const struct timeval& rhs) 
  • trunk/pdns/pdns/misc.cc

    r567 r597  
    379379  // we don't shuffle the rest 
    380380} 
     381 
     382 
     383void normalizeTV(struct timeval& tv) 
     384{ 
     385  if(tv.tv_usec > 1000000) { 
     386    ++tv.tv_sec; 
     387    tv.tv_usec-=1000000; 
     388  } 
     389  else if(tv.tv_usec < 0) { 
     390    --tv.tv_sec; 
     391    tv.tv_usec+=1000000; 
     392  } 
     393} 
     394 
     395const struct timeval operator+(const struct timeval& lhs, const struct timeval& rhs) 
     396{ 
     397  struct timeval ret; 
     398  ret.tv_sec=lhs.tv_sec + rhs.tv_sec; 
     399  ret.tv_usec=lhs.tv_usec + rhs.tv_usec; 
     400  normalizeTV(ret); 
     401  return ret; 
     402} 
     403 
     404const struct timeval operator-(const struct timeval& lhs, const struct timeval& rhs) 
     405{ 
     406  struct timeval ret; 
     407  ret.tv_sec=lhs.tv_sec - rhs.tv_sec; 
     408  ret.tv_usec=lhs.tv_usec - rhs.tv_usec; 
     409  normalizeTV(ret); 
     410  return ret; 
     411} 
  • trunk/pdns/pdns/misc.hh

    r567 r597  
    138138  inline void set();  //!< Reset the timer 
    139139  inline int udiff(); //!< Return the number of microseconds since the timer was last set. 
     140  void setTimeval(const struct timeval& tv) 
     141  { 
     142    d_set=tv; 
     143  } 
     144  struct timeval getTimeval() 
     145  { 
     146    return d_set; 
     147  } 
    140148private: 
    141149  struct timeval d_set; 
     
    232240string makeHexDump(const string& str); 
    233241void shuffle(vector<DNSResourceRecord>& rrs); 
     242 
     243void normalizeTV(struct timeval& tv); 
     244const struct timeval operator+(const struct timeval& lhs, const struct timeval& rhs); 
     245const struct timeval operator-(const struct timeval& lhs, const struct timeval& rhs); 
     246inline float makeFloat(const struct timeval& tv) 
     247{ 
     248  return tv.tv_sec + tv.tv_usec/1000000.0; 
     249} 
    234250#endif