qb  2.0.0.0
C++17 Actor Framework
qb Issue Watch Star Fork Follow @isndev
Loading...
Searching...
No Matches
qb::io::async::event::disconnected Struct Reference

Event triggered when a connection is closed or lost. More...

#include <disconnected.h>

Public Attributes

int reason = 0
 Reason code for the disconnection.

Detailed Description

Event triggered when a connection is closed or lost.

This event is passed to the derived class's on() method when a disconnection occurs in an I/O object (e.g., a TCP session). The reason field can contain a code indicating the cause of disconnection.

Usage Example:

class MyNetworkHandler : public qb::io::async::io<MyNetworkHandler> { // Or similar base
public:
// ... other methods ...
void on(qb::io::async::event::disconnected &&event) {
if (event.reason == 0) {
// Normal disconnection by peer or self
LOG_INFO("Connection closed normally.");
} else {
// Disconnection due to an error, event.reason might hold system errno
LOG_WARN("Connection lost, reason: " << event.reason);
}
// Perform cleanup, attempt reconnection, etc.
}
};
CRTP base class for managing bidirectional asynchronous I/O operations with protocol processing.
Definition io.h:938
#define LOG_INFO(X)
Info-level log macro (no-op if QB_STDOUT_LOG is not defined)
Definition io.h:229
#define LOG_WARN(X)
Warning-level log macro (no-op if QB_STDOUT_LOG is not defined)
Definition io.h:236

Member Data Documentation

◆ reason

int qb::io::async::event::disconnected::reason = 0

Reason code for the disconnection.

Typically 0 for a normal shutdown initiated by disconnect() or peer closing gracefully. Non-zero values often correspond to system error codes (errno) if the disconnection was due to an error detected by the underlying transport or OS.