summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
Diffstat (limited to 'methods')
-rw-r--r--methods/http.cc35
-rw-r--r--methods/http.h6
2 files changed, 11 insertions, 30 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;
diff --git a/methods/http.h b/methods/http.h
index d511196e3..5668f0b87 100644
--- a/methods/http.h
+++ b/methods/http.h
@@ -12,6 +12,7 @@
#include <apt-pkg/strutl.h>
+#include <chrono>
#include <iostream>
#include <memory>
#include <string>
@@ -36,11 +37,10 @@ class CircleBuf
std::string OutQueue;
unsigned long long StrPos;
unsigned long long MaxGet;
- struct timeval Start;
static unsigned long long BwReadLimit;
static unsigned long long BwTickReadData;
- static struct timeval BwReadTick;
+ static std::chrono::steady_clock::duration BwReadTick;
static const unsigned int BW_HZ;
unsigned long long LeftRead() const
@@ -85,8 +85,6 @@ class CircleBuf
bool WriteSpace() const {return InP - OutP > 0;};
void Reset();
- // Dump everything
- void Stats();
CircleBuf(HttpMethod const * const Owner, unsigned long long Size);
~CircleBuf();