/* * Copyright (C) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HTTP_SERVER_DEMO_H #define HTTP_SERVER_DEMO_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "nocopyable.h" namespace OHOS { namespace MediaAVCodec { class HttpServerDemo { public: explicit HttpServerDemo(); virtual ~HttpServerDemo(); void StartServer(); void StartServer(int32_t port); void StopServer(); private: void ServerLoopFunc(); static void FileReadFunc(int32_t connFd); static void CloseFd(int32_t &connFd, int32_t &fileFd, bool connCond, bool fileCond); static void GetRange(const std::string &recvStr, int32_t &startPos, int32_t &endPos); static void GetKeepAlive(const std::string &recvStr, int32_t &keep); static void GetFilePath(const std::string &recvStr, std::string &path); static int32_t SendRequestSize(int32_t &connFd, int32_t &fileFd, const std::string &recvStr); static int32_t SetKeepAlive(int32_t &connFd, int32_t &keepAlive, int32_t &keepIdle); std::atomic isRunning_ = false; std::unique_ptr serverLoop_ = nullptr; std::unique_ptr threadPool_ = nullptr; int32_t listenFd_ = 0; }; } // namespace MediaAVCodec } // namespace OHOS #endif