-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.h
49 lines (42 loc) · 1.67 KB
/
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
48
49
#pragma once
#include <vector>
#include <string>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <thread>
namespace http
{
enum class SubServerMessage : int
{
getResourse = 0,
sendResourse,
resourceSize,
res404
};
class ThreadPool;
class Server
{
public:
Server(std::vector<std::string> ips, std::string servIp, int port, ThreadPool *pool);
~Server();
void startListen();
int acceptConnection();
void handleUserConnection(int &connSock);
void sendResponse(int &connSock, const std::string &requestMethod, const std::string &requestURI, std::vector<std::string> tokens);
static int runSocket(std::string servIp, int port, sockaddr_in &servSockAddr, unsigned int &servSockAddrLen, __socket_type sockType);
ThreadPool *pool;
std::vector<int> interserverSockets;
private:
std::vector<std::string> allyServers;
int servSock;
int servPort;
struct sockaddr_in servSockAddr;
unsigned int servSockAddrLen;
void getFile(std::ostringstream &response, const std::string &requestURI, std::vector<std::string> tokens);
void postFile(std::ostringstream &response, const std::string &requestURI, const std::string &body);
std::string getContentType(const std::string &fileName);
std::string getLastModifiedTime(const std::string &fileName);
std::string sendMessageAndGetResponce(std::string ip, SubServerMessage message, std::string resourceName);
void formErrorResponse(int statusCode, const std::string &message, const std::string &statusText, std::ostringstream &response);
};
}