close method
Closes the connection
Implementation
@override
Future<void> close() async {
if (_closed) return;
_closed = true;
_legacyConnManager?.updateState(this, transport_state.ConnectionState.closing, error: null);
// _streams.clear(); // No streams to clear
// _muxedConn = null; // No muxedConn
// Clean up
await _socketSubscription?.cancel();
_socketSubscription = null;
// Complete any pending read with an error
if (_pendingReadCompleter != null && !_pendingReadCompleter!.isCompleted) {
_pendingReadCompleter!.completeError(StateError('Connection closed while a read was pending'));
_pendingReadCompleter = null;
}
_receiveBuffer.clear();
try {
await _socket.close();
} catch (e) {
_log.warning('Error closing socket: $e');
}
_connManagementScope?.done();
_legacyConnManager?.updateState(this, transport_state.ConnectionState.closed, error: null);
_readTimeout?.cancel();
_writeTimeout?.cancel();
_log.fine('TCPConnection($id) - Connection closed.');
}