Thread pool and main-thread callback dispatcher for networking.
More...
#include <Malena/Engine/Networking/NetworkManager.h>
|
| static void | autoFlush () |
| | Register flush() with AppManager's pre-render hook.
|
| static void | flush () |
| | Deliver all pending callbacks on the calling (main) thread.
|
| static void | initialize (std::size_t threadCount=4) |
| | Start the background thread pool.
|
| static void | shutdown () |
| | Stop all worker threads and discard pending work.
|
Thread pool and main-thread callback dispatcher for networking.
NetworkManager owns a pool of background worker threads. All HttpClient and WebSocketClient requests run on those threads so the render loop is never blocked. Completion callbacks are queued and delivered on the main thread when flush() is called.
Setup — call once in onInit()
void MyApp::onInit() override
{
}
static void autoFlush()
Register flush() with AppManager's pre-render hook.
static void initialize(std::size_t threadCount=4)
Start the background thread pool.
After that, every HttpClient and WebSocketClient callback fires on the main thread automatically — no manual synchronisation required.
Manual flush (advanced)
If you do not call autoFlush(), drain callbacks yourself each frame:
static void flush()
Deliver all pending callbacks on the calling (main) thread.
Shutdown
shutdown() is called automatically when AppManager destroys. You only need to call it manually if you want to tear down the pool before the application exits.
- See also
- HttpClient, WebSocketClient
Definition at line 49 of file NetworkManager.h.
◆ NetworkManager() [1/2]
| ml::NetworkManager::NetworkManager |
( |
| ) |
|
|
delete |
◆ NetworkManager() [2/2]
| ml::NetworkManager::NetworkManager |
( |
const NetworkManager & | | ) |
|
|
delete |
◆ autoFlush()
| void ml::NetworkManager::autoFlush |
( |
| ) |
|
|
static |
Register flush() with AppManager's pre-render hook.
After this call, pending network callbacks are delivered once per frame without any additional setup. Call this once in onInit().
◆ flush()
| void ml::NetworkManager::flush |
( |
| ) |
|
|
static |
Deliver all pending callbacks on the calling (main) thread.
Called automatically each frame if autoFlush() was used. Otherwise call this from onUpdate() to process responses.
◆ initialize()
| void ml::NetworkManager::initialize |
( |
std::size_t | threadCount = 4 | ) |
|
|
static |
Start the background thread pool.
Must be called before any HttpClient or WebSocketClient sends a request. Safe to call multiple times — subsequent calls are ignored if already initialised.
- Parameters
-
| threadCount | Number of worker threads. Defaults to 4. |
◆ operator=()
◆ shutdown()
| void ml::NetworkManager::shutdown |
( |
| ) |
|
|
static |
Stop all worker threads and discard pending work.
In-flight callbacks that have already been queued to the main thread are still delivered on the next flush(). Called automatically at application exit.
The documentation for this class was generated from the following file: