-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
44 lines (40 loc) · 929 Bytes
/
server.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
#pragma once
#include <iostream>
#include <stdexcept>
#include <errno.h>
#include <sys/socket.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unordered_map>
#include <thread>
#include <omp.h>
#include "connection.h"
#include "ringbuffer.h"
#include "sequencer.h"
#include "order.h"
#include "train.h"
using namespace std;
#define MAX_EPOLL_EVENTS 10
class Server {
public:
Server(const char* host, int port);
void start(int backlog);
void handle_orders();
private:
int listen_fd, epoll_fd, connect_fd;
const char* host;
int port;
struct epoll_event events[MAX_EPOLL_EVENTS];
unordered_map<int, Connection*> connections;
RingBuffer<Order> *ring;
Sequencer *sequencer;
long sequence;
Train *train;
thread *connection_handler, *order_handler;
void accept_connection();
void close_connection(int fd);
void receive_data(int fd);
void handle_connections();
};