WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
ThreadPoolWebServer.h
1#pragma once
2
3#include "Import/WebFrameworkCore.h"
4
5#include "ThreadPool.h"
6
7#include "BaseWebServer.h"
8#include "WebNetwork/Interfaces/IExecutorFunctionality.h"
9
10namespace framework
11{
13 public virtual BaseWebServer,
15 {
16 private:
17 class Client
18 {
19 private:
20 streams::IOSocketStream stream;
21 std::unordered_map<std::string, std::unique_ptr<BaseExecutor>> statefulExecutors;
22 std::function<void()> cleanup;
23 sockaddr address;
24 SSL* ssl;
25 SSL_CTX* context;
26 SOCKET clientSocket;
27 bool isBusy;
28 bool webExceptionAcquired;
29
30 public:
31 Client(SSL* ssl, SSL_CTX* context, SOCKET clientSocket, sockaddr address, std::function<void()>&& cleanup);
32
33 Client(const Client&) = delete;
34
35 Client(Client&&) noexcept = delete;
36
37 Client& operator = (const Client&) = delete;
38
39 Client& operator = (Client&&) noexcept = delete;
40
41 bool serve
42 (
43 SessionsManager& sessionsManager,
44 web::BaseTCPServer& server,
45 interfaces::IStaticFile& staticResources,
46 interfaces::IDynamicFile& dynamicResources,
47 sqlite::SQLiteManager& databaseManager,
48 ExecutorsManager& executorsManager,
49 ResourceExecutor& resourceExecutor,
50 threading::ThreadPool& threadPool
51 );
52
53 ~Client();
54 };
55
56 private:
57 threading::ThreadPool threadPool;
58 std::vector<Client*> clients;
59
60 private:
61 void serveClients();
62
63 private:
64 void clientConnection(const std::string& ip, SOCKET clientSocket, sockaddr address, std::function<void()>& cleanup) override;
65
66 void onInvalidConnectionReceive() override;
67
68 public:
70 (
71 const json::JSONParser& configuration,
72 const std::vector<utility::JSONSettingsParser>& parsers,
73 const std::filesystem::path& assets,
74 const std::filesystem::path& pathToTemplates,
75 uint64_t cachingSize,
76 std::string_view ip,
77 std::string_view port,
78 DWORD timeout,
79 const std::vector<std::string>& pathToSources,
80 uint32_t threadCount
81 );
82
83 ~ThreadPoolWebServer() = default;
84 };
85}
Used for sending asset files.