-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.h
executable file
·80 lines (62 loc) · 1.61 KB
/
connection.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <cstdlib>
#include "cbuffer.h"
#include "squeue.h"
#include "Ticks.h"
class connection_t {
public:
connection_t(int fd, int index);
virtual ~connection_t() {};
int get_fd();
int get_index();
queue_t<double>* get_msgs_rtt();
connection_buffer_t* get_read_buffer();
connection_buffer_t* get_write_buffer();
bool is_valid();
void add_unaknowledged_msg();
void record_msg_rtt();
void remove_connection();
protected:
int fd, index;
connection_buffer_t* write_buffer;
connection_buffer_t* read_buffer;
queue_t<TicksTime>* unaknowledged_msgs;// related to client only
queue_t<double>* msgs_rtt; // related to client only
bool valid;
//Following are variable that used for temporary storage.
TicksTime time;
long nsec;
double rtt;
};
inline int connection_t::get_fd(){
return fd;
}
inline int connection_t::get_index(){
return index;
}
inline queue_t<double>* connection_t::get_msgs_rtt(){
return msgs_rtt;
}
inline connection_buffer_t* connection_t::get_read_buffer(){
return write_buffer;
}
inline connection_buffer_t* connection_t::get_write_buffer(){
return read_buffer;
}
inline bool connection_t::is_valid(){
return valid;
}
inline void connection_t::add_unaknowledged_msg() {
time.setNow();
unaknowledged_msgs->push(time);
}
inline void connection_t::record_msg_rtt() {
time.setNow();
rtt = (time - unaknowledged_msgs->front()).toDecimalUsec();
msgs_rtt->push(rtt);
unaknowledged_msgs->pop();
}