C++ APISession methods

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
TypeMeaning
voidNo result value. Successful completion only means the shutdown sequence finished without transport/runtime error.

Behavior notes

  • shutdown can be called after connect, 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.
  • shutdown is 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 on_shutdown(...) is registered, explicit shutdown invokes it too. For client-initiated shutdown, close_message.code is typically blaze::close_code::none and reason is usually not set.
  • After shutdown, the blaze::session object is still reusable. Call connect again 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++17 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;
}

Error handling

You can match generic failures against blaze::errc, for example: if (ec == blaze::errc::connection_lost).

Error conditionWhen it can happen
timed_outA sync overload exceeded the configured session timeout while waiting for shutdown completion.
operation_would_blockA sync overload was called from the library I/O thread.
connection_lostThe underlying transport was already broken while the close/shutdown sequence was running.
protocol_errorWebsocket/TLS shutdown failed because of a protocol-level transport problem.

On this page