dropPeer method

void dropPeer()

Simulates the peer dropping the link. Mirrors real backends, which close both the state and incoming streams on a peer-initiated disconnect.

Implementation

void dropPeer() {
  if (_closed) return;
  // Real transports zero their pending gauge during teardown and latch the
  // loss; the fake must behave identically or unit tests exercise a gauge
  // contract that exists nowhere in production.
  _txDroppedBytes += _pendingWriteBytes;
  _pendingWriteBytes = 0;
  _closed = true;
  _current = ConnectionState.disconnected;
  _state.add(ConnectionState.disconnected);
  if (!_state.isClosed) unawaited(_state.close());
  if (!_incoming.isClosed) unawaited(_incoming.close());
}