summaryrefslogtreecommitdiff
path: root/bot/include
diff options
context:
space:
mode:
authorgarder500 <65552225+garder500@users.noreply.github.com>2025-05-01 14:35:24 +0200
committerGitHub <noreply@github.com>2025-05-01 14:35:24 +0200
commit3d758ad615e09c18befacad5c6eb0a6ae7ad0d23 (patch)
tree0c94147f2d9f94a7503269359103f7098a96bc35 /bot/include
parent23cba7cd6b32b7c5db98aa5a3f9206d4bce07902 (diff)
parent5c50f36cca528c586e72d389c35774ecb64091be (diff)
Merge pull request #2 from ketsuna-org/main
Refactor le serveur webhook HTTP pour améliorer la gestion des événem…
Diffstat (limited to 'bot/include')
-rw-r--r--bot/include/http_webhook_server.hpp29
1 files changed, 24 insertions, 5 deletions
diff --git a/bot/include/http_webhook_server.hpp b/bot/include/http_webhook_server.hpp
index a42829f..8ba6841 100644
--- a/bot/include/http_webhook_server.hpp
+++ b/bot/include/http_webhook_server.hpp
@@ -1,12 +1,18 @@
#pragma once
-#include <sys/epoll.h>
-#include <netinet/in.h>
#include <functional>
#include <string>
#include <unordered_map>
#include <system_error>
#include <sstream>
+#include <string>
+#include <netinet/in.h>
+
+#ifdef __linux__
+ #include <sys/epoll.h>
+#elif defined(__APPLE__)
+ #include <sys/event.h>
+#endif
class HttpWebhookServer {
public:
@@ -27,7 +33,8 @@ public:
HttpWebhookServer(uint16_t port, Handler handler);
~HttpWebhookServer();
-
+ void setupEpoll();
+ void handleEvents();
void start();
void stop();
@@ -39,17 +46,29 @@ private:
};
void setupSocket();
- void setupEpoll();
- void handleEvent(struct epoll_event* event);
+ void setupEventLoop();
+ void handleEvent(int fd, uint32_t events);
void handleClient(int fd);
void closeClient(int fd);
+ void registerFdForRead(int fd);
+ void modifyFdToWrite(int fd);
+ void sendToClient(int fd);
void parseHttpRequest(ClientContext& ctx, HttpRequest& req);
void buildHttpResponse(const HttpResponse& res, std::string& output);
int server_fd = -1;
+ int event_fd = -1;
int epoll_fd = -1;
bool running = false;
uint16_t port;
Handler request_handler;
std::unordered_map<int, ClientContext> clients;
+
+#ifdef __linux__
+ static constexpr int MAX_EVENTS = 64;
+ struct epoll_event events[MAX_EVENTS];
+#elif defined(__APPLE__)
+ static constexpr int MAX_EVENTS = 64;
+ struct kevent events[MAX_EVENTS];
+#endif
};