closeStatus property
How the connection was closed, by either side: the code and reason
of the close frame. null while it is open.
Implementation
@override
CloseStatus? get closeStatus {
final guard = _guard;
if (guard != null && guard.aborted) {
return _local;
}
final received = switch (_socket.closeCode) {
final code? => CloseStatus(code, switch (_socket.closeReason) {
final reason? when reason.isNotEmpty => reason,
_ => null,
}),
null => null,
};
// The input ended without a close frame (1006, no reason) after this
// side closed, or after the output met the error that broke the
// connection: _local has the status passed to close, or the error. (A
// close frame that arrived is the other side's answer: it wins.)
if (received != null &&
received.code == CloseStatus.noCloseFrame.code &&
_local != null) {
return _local;
}
// A broken connection: dart:io reports 1002 when the input side saw
// the error, 1006 when the output side saw it first (the guard then
// destroys the socket, and the input just ends without a close
// frame), 1005 for a close frame without a code whose answer failed,
// or nothing yet while the application holds the messages back.
// dart:io gives no reason then; _local has the error (or the status
// this side closed with first).
if (guard != null &&
guard.broken != null &&
(received == null ||
received.code == CloseStatus.protocolError.code ||
received.code == CloseStatus.noStatusCode.code ||
received.code == CloseStatus.noCloseFrame.code)) {
return _local;
}
return received ?? _local;
}