diff options
| author | delikesance <clauinangelo@proton.me> | 2025-05-01 14:57:30 +0200 | 
|---|---|---|
| committer | delikesance <clauinangelo@proton.me> | 2025-05-01 14:57:30 +0200 | 
| commit | 48e064b957a3f47321c3df9802749d45f6c33ce6 (patch) | |
| tree | 175bafb152c5ca5f30d02af4b93db02351b4cea3 /bot/include/http_webhook_server.hpp | |
| parent | 777a37336b5144ce39f2c815ea0fda4dc0ad0e2f (diff) | |
| parent | 26207c990abdb9ce7f2cc8e9e371d63fcb439d46 (diff) | |
Merge branch 'main' of github.com:delikesance/bot-creator-api
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  };  | 
