shutdown
Closes the current websocket session and ends the current connection lifecycle.
shutdown closes the current websocket connection for this blaze::session.
It is a transport/session-lifecycle method, not a Blazeauth packet usecase, so
it does not return blaze::status.
Function variants
void shutdown();
void shutdown(std::error_code& ec) noexcept;
void async_shutdown(std::function<void(std::error_code)> callback);
blaze::coro::awaitable_result<void> co_shutdown();No API status here
shutdown does not return blaze::status. Failures are reported through
std::error_code or std::system_error.
Result
void| Type | Meaning |
|---|---|
void | No result value. Successful completion only means the shutdown sequence finished without transport/runtime error. |
Behavior notes
shutdowncan be called afterconnect, even if the session was never initialized or authorized.- Explicit shutdown does not send a Blazeauth API packet and does not return any API-level status.
shutdownis idempotent. Repeating it after the session is already closed is treated as a successful no-op.- Pending API operations that have not completed yet are finished with
blaze::errc::shutdown. - If
set_shutdown_callback(...)is registered, explicitshutdowninvokes it too. For client-initiated shutdown,close_message.codeis typicallyblaze::close_code::noneandreasonis empty. - After
shutdown, theblaze::sessionobject is still reusable. Callconnectagain to start a fresh connection. - Sync overloads use the session timeout configured in the constructor or via
with_timeout(...). - Coroutine overloads are available only when the library is built with coroutine support.
Example
Compilation note
Synchronous and Asynchronous examples compile 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;
try {
const blaze::api_server server = session.connect();
std::cout << "Connected to server location: " << server.location << '\n';
session.shutdown();
std::cout << "Session shutdown completed\n";
} catch (const std::system_error& e) {
print_error_code("Shutdown failed", e.code());
return 1;
}
return 0;
}#include "blazeauth/api/api.hpp"
#include <future>
#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;
std::promise<int> completion;
std::future<int> result = completion.get_future();
session.async_connect([&session, &completion](std::error_code connect_ec, blaze::api_server server) {
if (connect_ec) {
print_error_code("Connect failed", connect_ec);
completion.set_value(1);
return;
}
std::cout << "Connected to server location: " << server.location << '\n';
session.async_shutdown([&completion](std::error_code shutdown_ec) {
if (shutdown_ec) {
print_error_code("Shutdown failed", shutdown_ec);
completion.set_value(1);
return;
}
std::cout << "Session shutdown completed\n";
completion.set_value(0);
});
});
return result.get();
}Project must be built with C++20 support and with coroutine support available both in the language mode and in the standard library implementation for this example to compile correctly.
#include "blazeauth/api/api.hpp"
#include <future>
#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";
}
#if BLAZEAUTH_HAS_COROUTINES
blaze::coro::task<std::error_code> run_example(blaze::session& session) {
const auto [connect_ec, server] = co_await session.co_connect();
if (connect_ec) {
co_return connect_ec;
}
std::cout << "Connected to server location: " << server.location << '\n';
const auto [shutdown_ec] = co_await session.co_shutdown();
co_return shutdown_ec;
}
int main() {
blaze::session session;
std::promise<std::error_code> completion;
std::future<std::error_code> result = completion.get_future();
blaze::coro::co_spawn([&session, &completion]() -> blaze::coro::task<void> {
const std::error_code ec = co_await run_example(session);
completion.set_value(ec);
co_return;
}());
const std::error_code ec = result.get();
if (ec) {
print_error_code("Shutdown failed", ec);
return 1;
}
std::cout << "Session shutdown completed\n";
return 0;
}
#else
int main() {
std::cout << "This example requires coroutine support in the Blazeauth library build.\n";
return 0;
}
#endifError handling
You can match generic failures against blaze::errc, for example:
if (ec == blaze::errc::connection_lost).
| Error condition | When it can happen |
|---|---|
timed_out | A sync overload exceeded the configured session timeout while waiting for shutdown completion. |
operation_would_block | A sync overload was called from the library I/O thread. |
connection_lost | The underlying transport was already broken while the close/shutdown sequence was running. |
protocol_error | Websocket/TLS shutdown failed because of a protocol-level transport problem. |