-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinux_tcp_socket.hpp
More file actions
59 lines (47 loc) · 1.34 KB
/
linux_tcp_socket.hpp
File metadata and controls
59 lines (47 loc) · 1.34 KB
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
#ifndef HTTPWEBSERVER_LINUX_TCP_SOCKET_HPP__
#define HTTPWEBSERVER_LINUX_TCP_SOCKET_HPP__
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include "common.hpp"
#include "raw_socket.hpp"
#include "pipe.hpp"
#include "connection.hpp"
#include "interfaces/socket.hpp"
#include "connection.hpp"
#include "timeval.hpp"
namespace nt { namespace http {
typedef void (* event_callback)(void*, void*);
class __HttpWebServerSocketPort__ LinuxTcpSocket :
public nt::http::interfaces::Socket
{
private:
std::shared_ptr<Connection> server;
std::shared_ptr<Connection> pipe;
private:
unsigned int queue_count;
const unsigned int max_connections;
std::vector<std::shared_ptr<Connection>> connections;
fd_set read_list;
fd_set write_list;
fd_set error_list;
public:
LinuxTcpSocket();
~LinuxTcpSocket() noexcept = default;
void bind(const char*, const char*);
void bind(const char*, const unsigned short);
void listen(const unsigned int, event_callback);
void open();
void close();
private:
void reset_socket_lists();
unsigned short get_last_socket();
bool select();
inline bool is_new_connection(const Connection*);
void handle_new_connection();
void receive_data(SOCKET);
void write_data(SOCKET);
};
}}
#endif /* HTTPWEBSERVER_LINUX_TCP_SOCKET_HPP__ */