-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabaseutils.h
More file actions
41 lines (32 loc) · 993 Bytes
/
Copy pathdatabaseutils.h
File metadata and controls
41 lines (32 loc) · 993 Bytes
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
#define PORT "8080"
#include <sys/socket.h>
#include <unistd.h> // For close()
#include <string>
#include <iostream>
#include <vector>
#include <chrono>
const ssize_t MAX_BUFFER_SIZE = 4096;
class Connection {
public:
int fd;
std::vector<u_int8_t> read_buffer;
std::vector <u_int8_t> write_buffer;
size_t read_offset;
size_t write_offset;
bool should_close;
std::chrono::steady_clock::time_point last_activity;
Connection(int socket_fd)
: fd(socket_fd), write_offset(0), should_close(false),
last_activity(std::chrono::steady_clock::now()) {
read_buffer.reserve(4096);
write_buffer.reserve(4096);
}
bool has_pending_write() const {
return write_offset < write_buffer.size();
}
void update_activity() {
last_activity = std::chrono::steady_clock::now();
}
};
int send_data(int fd, const char * message, ssize_t bytes);
int recieve_data(int fd, char * buffer, ssize_t bytes);