diff options
| author | delikesance <95828763+delikesance@users.noreply.github.com> | 2025-05-01 14:41:11 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-01 14:41:11 +0200 | 
| commit | 26207c990abdb9ce7f2cc8e9e371d63fcb439d46 (patch) | |
| tree | bfe7ffb3281fb8e8cb0c52346b39e821cf2b43d2 /bot/include | |
| parent | 39bfa6bca0b10a917258b87f722557339cf12e3d (diff) | |
| parent | 5c50f36cca528c586e72d389c35774ecb64091be (diff) | |
Merge branch 'ketsuna-org:main' into main
Diffstat (limited to 'bot/include')
| -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  };  | 
