Bredbandskollen CLI  1.2
Asynchronous network task engine
pingsweeptask.h
1 #pragma once
2 
3 #include <vector>
4 #include <deque>
5 #include "../json11/json11.hpp"
6 #include "../http/httpclienttask.h"
7 
8 class PingSweepTask : public HttpClientTask {
9 public:
10  PingSweepTask(const std::string &obj, const HttpHost &server);
11  double start() override;
12  double timerEvent() override;
13  void newRequest(HttpClientConnection *) override;
14  bool requestComplete(HttpClientConnection *conn) override;
15  std::string cacheLabel() override {
16  return std::string(); // Don't store in keep-alive cache
17  }
18  std::string getResult() {
19  if (results.empty())
20  return std::string();
21  std::string res = results.front();
22  results.pop_front();
23  return res;
24  }
25 private:
26  std::string json_err;
27  json11::Json config;
28  std::map<std::string, TimePoint> requests;
29  std::string best_host;
30  std::deque<std::string> results;
31  double best_time = 1e6;
32 };
HTTP/1.1 client protocol.
Definition: httpclientconnection.h:39
API for HTTP clients.
Definition: httpclienttask.h:11
The host name and port number of a HTTP host.
Definition: httphost.h:17
Definition: pingsweeptask.h:8
double start() override
Definition: pingsweeptask.cpp:9
void newRequest(HttpClientConnection *) override
Initiate next request, or ignore to close connection.
Definition: pingsweeptask.cpp:28
double timerEvent() override
Definition: pingsweeptask.cpp:23
bool requestComplete(HttpClientConnection *conn) override
Called when response has been fully read.
Definition: pingsweeptask.cpp:38