diff options
Diffstat (limited to 'bot/include/http_webhook_server.hpp')
| -rw-r--r-- | bot/include/http_webhook_server.hpp | 29 |
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 }; |
