close method
Closes the connection
Implementation
@override
Future<void> close() async {
if (_closed) return;
final currentState = _manager.getState(this);
if (currentState == null ||
currentState == transport_state.ConnectionState.closed ||
currentState == transport_state.ConnectionState.error) {
return;
}
_closed = true;
_readTimeout?.cancel();
_writeTimeout?.cancel();
try {
if (currentState != transport_state.ConnectionState.closing) {
_manager.updateState(this, transport_state.ConnectionState.closing, error: null);
}
await _stream.close();
if (_manager.getState(this) != null) {
_manager.updateState(this, transport_state.ConnectionState.closed, error: null);
}
} catch (e) {
if (_manager.getState(this) != null) {
_manager.updateState(this, transport_state.ConnectionState.error, error: e);
}
rethrow;
}
}