/* * IXHttpServer.h * Author: Benjamin Sergeant * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. */ #pragma once #include "IXHttp.h" #include "IXSocketServer.h" #include "IXWebSocket.h" #include #include #include #include #include #include #include // pair namespace ix { class HttpServer final : public SocketServer { public: using OnConnectionCallback = std::function)>; HttpServer(int port = SocketServer::kDefaultPort, const std::string& host = SocketServer::kDefaultHost, int backlog = SocketServer::kDefaultTcpBacklog, size_t maxConnections = SocketServer::kDefaultMaxConnections, int addressFamily = SocketServer::kDefaultAddressFamily, int timeoutSecs = HttpServer::kDefaultTimeoutSecs); virtual ~HttpServer(); virtual void stop() final; void setOnConnectionCallback(const OnConnectionCallback& callback); void makeRedirectServer(const std::string& redirectUrl); void makeDebugServer(); private: // Member variables OnConnectionCallback _onConnectionCallback; std::atomic _connectedClientsCount; const static int kDefaultTimeoutSecs; int _timeoutSecs; // Methods virtual void handleConnection(std::unique_ptr, std::shared_ptr connectionState) final; virtual size_t getConnectedClientsCount() final; void setDefaultConnectionCallback(); }; } // namespace ix