-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathSpeedTestClient.h
45 lines (39 loc) · 1.21 KB
/
SpeedTestClient.h
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
//
// Created by Francesco Laurita on 5/30/16.
//
#ifndef SPEEDTEST_SPEEDTESTCLIENT_H
#define SPEEDTEST_SPEEDTESTCLIENT_H
#include <ctime>
#include <netdb.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include <chrono>
#include <unistd.h>
#include "SpeedTest.h"
#include "DataTypes.h"
class SpeedTestClient {
public:
SpeedTestClient(const ServerInfo& serverInfo, bool qualityHost = false);
~SpeedTestClient();
bool connect();
bool ping(long &millisec);
bool upload(const long size, const long chunk_size, long &millisec);
bool download(const long size, const long chunk_size, long &millisec);
bool ploss(const int size, const int wait_millisec, int &nploss);
float version();
const std::pair<std::string, int> hostport();
void close();
static std::time_t now();
private:
bool mkSocket();
ServerInfo mServerInfo;
int mSocketFd;
bool mQualityHost;
float mServerVersion;
static bool readLine(int& fd, std::string& buffer);
static bool writeLine(int& fd, const std::string& buffer);
};
typedef bool (SpeedTestClient::*opFn)(const long size, const long chunk_size, long &millisec);
#endif //SPEEDTEST_SPEEDTESTCLIENT_H