C++ APISession methods

ping

Measures websocket ping/pong round-trip time for the current session.

ping measures transport-level websocket latency for the current blaze::session. Unlike API operations such as initialize or authorize, it does not return blaze::status and does not depend on application initialization state.

Function variants

std::chrono::milliseconds ping();
std::chrono::milliseconds ping(std::error_code& ec) noexcept;
void async_ping(std::function<void(std::error_code, std::chrono::milliseconds)> callback);
blaze::coro::awaitable_result<std::chrono::milliseconds> co_ping();

No API status here

ping measures websocket ping/pong round-trip time. Failures are reported through std::error_code or std::system_error, not through blaze::status.

Result

std::chrono::milliseconds
TypeMeaning
std::chrono::millisecondsElapsed time between sending websocket ping and receiving pong.

Behavior notes

  • Call ping after a successful connect.
  • ping does not require initialize.
  • The returned value measures websocket transport round-trip time, not Blazeauth packet handler execution time.
  • ping participates in the same session send-rate limiting as other outgoing operations.
  • Sync overloads use the session timeout configured in the constructor or via with_timeout(...).

Example

Compilation note

Synchronous and Asynchronous examples compile in the same form from C++17 to C++26.

#include "blazeauth/api/api.hpp"

#include <chrono>
#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';

    const std::chrono::milliseconds rtt = session.ping();
    std::cout << "Ping RTT: " << rtt.count() << " ms\n";

    session.shutdown();
  } catch (const std::system_error& e) {
    print_error_code("Ping 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
not_connectedping was called while the session was not connected.
rate_limit_reachedSession send rate limit was reached before ping could be started.
timed_outA sync overload exceeded the configured session timeout while waiting for pong.
operation_would_blockA sync overload was called from the library I/O thread.
connection_closedServer closed the websocket before ping completed.
connection_lostNetwork connection was lost while waiting for pong.
protocol_errorTransport or websocket protocol handling failed during the ping flow.

On this page