-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerSelector.h
More file actions
46 lines (36 loc) · 1.86 KB
/
Copy pathServerSelector.h
File metadata and controls
46 lines (36 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// Interactive server picker and standalone latency prober.
//
#ifndef SPEEDTEST_SERVERSELECTOR_H
#define SPEEDTEST_SERVERSELECTOR_H
#include <string>
#include <vector>
#include "DataTypes.h"
// Result of a single latency probe. Sub-millisecond resolution, unlike
// SpeedTestClient::ping(), so nearby servers stay distinguishable.
typedef struct probe_result_t {
enum State { Untested, Queued, Testing, Ok, Failed, Unsupported };
State state = Untested;
double latency_ms = 0.0;
std::string version;
} ProbeResult;
// Case-insensitive substring match against city, sponsor, country and host.
bool serverMatches(const ServerInfo& server, const std::string& needle);
std::vector<ServerInfo> filterServers(const std::vector<ServerInfo>& servers, const std::string& needle);
// Connects, handshakes and pings a single server. Fully self-contained: every
// socket operation has a hard timeout, so it is safe to run from worker threads.
ProbeResult probeServer(const ServerInfo& server, int samples = 4, int timeout_ms = 2000);
// Probes every given server in parallel and blocks until all are done.
std::vector<ProbeResult> probeServers(const std::vector<ServerInfo>& servers, const std::string& minVersion);
// Full-screen picker. Returns false when the user aborts (q / Esc / Ctrl-C).
bool selectServerInteractive(const std::vector<ServerInfo>& servers,
const IPInfo& client,
const std::string& initialFilter,
const std::string& minVersion,
ServerInfo& chosen);
// Renders the same table non-interactively.
void printServerTable(const std::vector<ServerInfo>& servers,
const std::vector<ProbeResult>& results,
const IPInfo& client);
bool stdinIsInteractive();
#endif //SPEEDTEST_SERVERSELECTOR_H