49 lines
1.3 KiB
C
49 lines
1.3 KiB
C
|
#pragma once
|
||
|
|
||
|
#include "EPollManager.h"
|
||
|
#include "SocketManager.h"
|
||
|
#include "Map.h"
|
||
|
#include "Router.h"
|
||
|
#include "RequestHandler.h"
|
||
|
#include "MiddleWareHandler.h"
|
||
|
#include "Route.h"
|
||
|
|
||
|
namespace VWeb {
|
||
|
class Server {
|
||
|
public:
|
||
|
Server();
|
||
|
// Will Load SharedLibs from subdirectory
|
||
|
// This will allow that VWeb will run as Standalone and will load .so files
|
||
|
// without recompiling itself
|
||
|
void LoadSharedLibs();
|
||
|
void Start();
|
||
|
void Join() { m_WorkerThread->join(); }
|
||
|
void Stop() { m_IsExit = true; }
|
||
|
Ref<Router> &GetRouter() { return m_Router; }
|
||
|
Ref<ServerConfig> &GetServerConfig() { return m_ServerConfig; }
|
||
|
void AddRoute(const std::string &path, const Ref<Route> &route);
|
||
|
void RemoveRoute(const std::string &path);
|
||
|
|
||
|
Ref<MiddleWareHandler> &Middleware();
|
||
|
|
||
|
protected:
|
||
|
void Execute();
|
||
|
void OutgoingExecute(epoll_event &event);
|
||
|
void IncomingExecute(epoll_event &event);
|
||
|
void HandleRequestReading(epoll_event &event);
|
||
|
void CreateRequest(int sockID);
|
||
|
|
||
|
protected:
|
||
|
Ref<Router> m_Router;
|
||
|
Ref<ServerConfig> m_ServerConfig;
|
||
|
Ref<RequestHandler> m_RequestHandler;
|
||
|
SafeMap<int, Accept> m_RawRequest{60000};
|
||
|
SafeMap<int, SendData> m_OutRequest{60000};
|
||
|
Ref<std::thread> m_WorkerThread;
|
||
|
std::mutex m_Mutex;
|
||
|
bool m_IsExit{false};
|
||
|
|
||
|
protected:
|
||
|
friend RequestHandler;
|
||
|
};
|
||
|
}
|