LCOV - code coverage report
Current view: top level - source/network - HttpServer.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 14 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #include "precompiled.h"
      19             : 
      20             : #include "HttpServer.h"
      21             : 
      22             : #include "ps/Future.h"
      23             : #include "ps/TaskManager.h"
      24             : 
      25             : #include <httplib.h>
      26             : #include <queue>
      27             : 
      28             : namespace
      29             : {
      30           0 : class TaskQueueAdapter : public httplib::TaskQueue
      31             : {
      32             : public:
      33           0 :     bool enqueue(std::function<void()> fn) override
      34             :     {
      35             :         // Remove finished
      36           0 :         while (!m_Futures.empty() && m_Futures.front().IsDone())
      37             :         {
      38           0 :             m_Futures.front().Get();
      39           0 :             m_Futures.pop();
      40             :         }
      41             : 
      42           0 :         m_Futures.push({g_TaskManager, fn});
      43           0 :         return true;
      44             :     }
      45             : 
      46           0 :     void shutdown() override
      47             :     {
      48           0 :         m_Futures = {};
      49           0 :     }
      50             : private:
      51             :     std::queue<Future<void>> m_Futures;
      52             : };
      53             : } // namespace
      54             : 
      55             : namespace PS::Net
      56             : {
      57           0 : std::unique_ptr<httplib::Server> createHttpServer() {
      58           0 :     auto server = std::make_unique<httplib::Server>();
      59           0 :     server->new_task_queue = [] { return new TaskQueueAdapter(); };
      60           0 :     return server;
      61             : }
      62             : } // namespace PS::Net

Generated by: LCOV version 1.16