C++ APISession methods
set_connection_resumed_callback
Registers a callback that runs after automatic session resumption succeeds.
set_connection_resumed_callback installs a hook that runs after automatic
session resumption succeeds.
Function variants
void set_connection_resumed_callback(std::function<void()> callback);Runs on the library I/O thread
Do not call synchronous blaze::session methods from this callback. If you
need to continue work from here, stay on async API or hand control back to
your own thread/executor.
Callback signature
void()Behavior notes
- This callback fires only after automatic resumption succeeded following unexpected connection loss.
- It is not called on the initial
connect(). - It is not called if session resumption is disabled.
- It is not called if the resumption attempt fails and the session shuts down instead.
- After a successful resumption, the session continues with the previously restored server-side state.
- On the current server implementation, panel-events subscription state is preserved across valid session resumption.
- Pass
nullptror an emptystd::functionto clear the callback.
Example
Compilation note
This example compiles in the same form from C++14 to C++26.
#include "blazeauth/api/api.hpp"
#include <iostream>
#include <string>
#include <system_error>
void print_error_code(const std::string& context, const std::error_code& ec) {
std::cout << context << ": " << ec.message() << " ("
<< ec.value() << " : " << ec.category().name() << ")\n";
}
int main() {
blaze::session session;
session.set_session_resumption_enabled(true);
session.set_connection_resumed_callback([]() {
std::cout << "Session was resumed\n";
});
try {
const blaze::api_server server = session.connect();
std::cout << "Connected to server location: " << server.location << '\n';
std::cout << "If the transport is lost and resumption succeeds, the callback will run\n";
session.shutdown();
} catch (const std::system_error& e) {
print_error_code("Connect or shutdown failed", e.code());
return 1;
}
return 0;
}