| Home | API Documentation |
Internal: Mug · ThorsMug · ThorsSlack · NisseServer · NisseHTTP · ThorsSocket · ThorsCrypto · ThorsSerializer · ThorsMongo · ThorsLogging · ThorsIOUtil
Implementation details for the Mug configurable HTTP server application.
Source: third/Mug/src/Mug/
Mug is a standalone executable that extends NisseServer:
┌──────────────────────────────────────────────────┐
│ mug (executable) │
│ MugCLA (argument parsing) │
│ MugConfig (JSON configuration) │
├──────────────────────────────────────────────────┤
│ MugServer │
│ Extends NisseServer │
│ + DLLibMap (plugin management) │
│ + LibraryChecker (hot-reload timer) │
│ + PyntHTTPControl (control endpoint) │
├──────────────────────────────────────────────────┤
│ NisseServer / NisseHTTP │
└──────────────────────────────────────────────────┘
| File | Purpose |
|---|---|
mug.cpp |
Main entry point |
MugServer.h/.cpp |
Server class extending NisseServer |
MugConfig.h |
Configuration structs with ThorsSerializer traits |
MugArgs.h/.cpp |
Command-line argument storage |
MugCLA.h/.cpp |
Command-line argument parser |
DLLib.h/.cpp |
Dynamic library loading and management |
Extends NisseServer with:
PyntHTTPControl control: HTTP control endpoint on the configured control port.Hanlders servers: A std::vector<HTTPHandler>, one per configured port.DLLibMap libraries: Manages all loaded shared libraries.LibraryChecker libraryChecker: A TimerAction that periodically calls checkLibrary().HTTPHandler per configured port.actions and calls libraries.load(handler, pluginInfo) to load the shared library and register its routes.certPath is present.libraryCheckTime > 0, registers the LibraryChecker timer.The LibraryChecker timer calls checkLibrary() which delegates to DLLibMap::checkAll(). Each DLLib compares the file’s modification time against the stored lastModified. If changed:
plugin->stop(handler) to unregister routes.dlclose() on the old library.dlopen() on the new library.MugPlugin*.plugin->start(handler) to register new routes.dlopen(path, RTLD_NOW) loads the shared library.dlsym(lib, "mugPlugin") retrieves the MugFunc factory function.MugPlugin*.plugin->start(handler) registers the plugin’s routes.plugin->stop(handler) unregisters routes.MugPlugin* is deleted.dlclose(lib) unloads the shared library.dlerror() is checked after each dlopen/dlsym/dlclose call. Errors are logged and thrown as std::runtime_error.
The configuration structs use ThorsSerializer for JSON deserialization:
ThorsAnvil_MakeTrait(Plugin, pluginPath, config);
ThorsAnvil_MakeTrait(PortConfig, port, certPath, actions);
ThorsAnvil_MakeTrait(MugConfig, servers, controlPort, libraryCheckTime);
The config field in Plugin uses ThorsAnvil::Serialize::AnyBlock to accept arbitrary JSON that is passed through to the plugin factory function as a string.
Parses arguments from argv:
--config <file> / -c <file>--silent / -s--help / -h--log-file <path> / --log-sys <name> / --log-level <level>If --config is not specified, searches a list of default paths (searchPath) for a configuration file.
Stores the parsed results:
help: whether to display helpsilent: headless mode flagconfigPath: resolved path to the config fileImplements MugCLAInterface to receive parsed values from MugCLA.
MugArgs.help flag set, display help and exit.jsonImporter(config).MugServer(config, mode).server.run() (blocks until stopped).MugServer uses 4 worker threads (hardcoded workerCount = 4). The hot-reload check runs on the main thread (via the timer callback), so no locking is needed for plugin loading/unloading since the Store command queue pattern ensures all mutations happen on the main thread.