-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathServer.h
47 lines (34 loc) · 936 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
45
46
47
#pragma once
#include <vector>
#include <thread>
#include "SocketWrapper.h"
#include <memory>
#include "Memory.h"
#include "ClientState.h"
#ifdef _WIN32
#include <WinSock2.h>
#else
#include <netinet/in.h>
#endif
class Server
{
private:
CreateSocketFunc createSocket = nullptr;
Memory* memory;
std::shared_ptr<SocketWrapper> serverSocket = nullptr;
struct sockaddr_in server;
bool bStop = false;
std::thread* serverThread = nullptr;
std::vector<std::thread*> clientThreads;
ClientState sharedState;
void handleClientConnection(struct sockaddr_in clientInfo, std::shared_ptr<SocketWrapper> clientSocket);
public:
Server(struct sockaddr_in server, std::shared_ptr<SocketWrapper> serverSocket, Memory* memory);
~Server();
void setSocketFactory(CreateSocketFunc func);
std::shared_ptr<SocketWrapper> socket();
bool init();
bool start();
void stop();
void join();
};