-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTTPHandler.h
45 lines (34 loc) · 1.04 KB
/
HTTPHandler.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
#pragma once
#include "Socket.h"
#include <map>
#include <string>
#include <iostream>
class HTTPHandler : public Socket{
private:
static const std::string kdelim;
static const std::string kmethod_key;
static const std::string kproto_key;
static const std::string kpath_key;
static const std::string kbody_key;
static const std::string kbody_len_key;
// current throughput rate into this socket
double T_cur;
static double alpha;
public:
HTTPHandler(const char* ip, int port):Socket(ip,port),T_cur(0) {
}
HTTPHandler(int sd, struct sockaddr_in sin):Socket(sd,sin),T_cur(0){}
std::map<std::string, std::string> gen_header(const std::string& hdr);
std::string recv();
double get_throughput() {
return T_cur;
}
void update_throughput(double t_new) {
T_cur = alpha * t_new + (1 - alpha) * T_cur;
std::cout << "Estimated Throughput: " << T_cur << std::endl;
}
static void set_alphas(double a) {
assert(a >= 0 && a <= 1);
alpha = a;
}
};