forked from taganaka/SpeedTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SpeedTestClient.h
43 lines (36 loc) · 1.05 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
//
// 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:
explicit SpeedTestClient(const ServerInfo& serverInfo);
~SpeedTestClient();
bool connect();
bool ping(long &millisec);
bool upload(long size, long chunk_size, long &millisec);
bool download(long size, long chunk_size, long &millisec);
float version();
const std::pair<std::string, int> hostport();
void close();
private:
bool mkSocket();
ServerInfo mServerInfo;
int mSocketFd;
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