summaryrefslogtreecommitdiff
path: root/methods/http.cc
diff options
context:
space:
mode:
Diffstat (limited to 'methods/http.cc')
-rw-r--r--methods/http.cc35
1 files changed, 9 insertions, 26 deletions
diff --git a/methods/http.cc b/methods/http.cc
index 3862497a8..2e7fca307 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -25,6 +25,7 @@
#include <apt-pkg/proxy.h>
#include <apt-pkg/strutl.h>
+#include <chrono>
#include <cstring>
#include <iostream>
#include <sstream>
@@ -49,7 +50,7 @@ using namespace std;
unsigned long long CircleBuf::BwReadLimit=0;
unsigned long long CircleBuf::BwTickReadData=0;
-struct timeval CircleBuf::BwReadTick={0,0};
+std::chrono::steady_clock::duration CircleBuf::BwReadTick{0};
const unsigned int CircleBuf::BW_HZ=10;
// CircleBuf::CircleBuf - Circular input buffer /*{{{*/
@@ -98,18 +99,17 @@ bool CircleBuf::Read(std::unique_ptr<MethodFd> const &Fd)
unsigned long long const BwReadMax = CircleBuf::BwReadLimit/BW_HZ;
if(CircleBuf::BwReadLimit) {
- struct timeval now;
- gettimeofday(&now,0);
+ auto const now = std::chrono::steady_clock::now().time_since_epoch();
+ auto const d = now - CircleBuf::BwReadTick;
- unsigned long long d = (now.tv_sec-CircleBuf::BwReadTick.tv_sec)*1000000 +
- now.tv_usec-CircleBuf::BwReadTick.tv_usec;
- if(d > 1000000/BW_HZ) {
+ auto const tickLen = std::chrono::microseconds(std::chrono::seconds(1)) / BW_HZ;
+ if(d > tickLen) {
CircleBuf::BwReadTick = now;
CircleBuf::BwTickReadData = 0;
- }
-
+ }
+
if(CircleBuf::BwTickReadData >= BwReadMax) {
- usleep(1000000/BW_HZ);
+ usleep(tickLen.count());
return true;
}
}
@@ -134,8 +134,6 @@ bool CircleBuf::Read(std::unique_ptr<MethodFd> const &Fd)
return false;
}
- if (InP == 0)
- gettimeofday(&Start,0);
InP += Res;
}
}
@@ -267,21 +265,6 @@ bool CircleBuf::Write(string &Data)
return true;
}
/*}}}*/
-// CircleBuf::Stats - Print out stats information /*{{{*/
-// ---------------------------------------------------------------------
-/* */
-void CircleBuf::Stats()
-{
- if (InP == 0)
- return;
-
- struct timeval Stop;
- gettimeofday(&Stop,0);
-/* float Diff = Stop.tv_sec - Start.tv_sec +
- (float)(Stop.tv_usec - Start.tv_usec)/1000000;
- clog << "Got " << InP << " in " << Diff << " at " << InP/Diff << endl;*/
-}
- /*}}}*/
CircleBuf::~CircleBuf() /*{{{*/
{
delete [] Buf;