C++20 Microservice Bootstrapping Framework
/users/{id}?{queryParam1}={valueParam1}
_FORTIFY_SOURCE=3
and other security related flags on non-windows builds when using hardeningNone
The most exciting feature addition is the async file I/O, which emulates rust's tokio's async functions:
// enqueue reading the file on another thread and co_await its result
// not using auto to show the type in example. Using auto would be a lot easier here.
tl::expected<std::string, Ichor::FileIOError> ret = co_await async_io_svc->read_whole_file("AsyncFileIO.txt");
if(!ret || ret != "This is a test") {
fmt::print("Couldn't read file\n");
co_return {};
}
// enqueue writing to file (automatically overwrites if already exists)
tl::expected<void, Ichor::FileIOError> ret2 = co_await async_io_svc->write_file("AsyncFileIO.txt", "Overwrite");
if(!ret2) {
fmt::print("Couldn't write file\n");
co_return {};
}
ret = co_await async_io_svc->read_whole_file("AsyncFileIO.txt");
if(!ret || ret != "Overwrite") {
fmt::print("Couldn't read file\n");
co_return {};
}
More information on the async I/O can be found in the docs.
Full Changelog: https://github.com/volt-software/Ichor/compare/v0.2.0...v0.3.0
Full Changelog: https://github.com/volt-software/Ichor/compare/v0.1.0...v0.2.0
co_await
:
Ichor now supports using co_await to wait on a response on HTTP requests:
auto toSendMsg = _serializationAdmin->serialize(PingMsg{_sequence});
HttpResponse &response = *co_await _connectionService->sendAsync(HttpMethod::post, "/ping", {}, std::move(toSendMsg)).begin();
if(response.status == HttpStatus::ok) {
auto msg = _serializationAdmin->deserialize<PingMsg>(response.body);
co_return msg;
} else {
co_return std::unique_ptr<PingMsg>{};
}
For more example code, please look at the ping pong example.
To instantiate the Multimap based queue:
#include <ichor/event_queues/MultimapQueue.h>
using namespace Ichor;
int main(int argc, char *argv[]) {
// ...
auto queue = std::make_unique<MultimapQueue>();
auto &dm = queue->createManager();
// ...
}
And the sdevent based one:
#include <ichor/event_queues/SdeventQueue.h>
using namespace Ichor;
int main(int argc, char *argv[]) {
// ...
auto queue = std::make_unique<SdeventQueue>();
auto &dm = queue->createManager();
dm.store(&dm, std::memory_order_release);
auto *loop = queue->createEventLoop();
// ...
queue->start(DoNotCaptureSigInt);
int r = sd_event_loop(loop);
// ...
}
First alpha release of Ichor.