setWindow method

void setWindow(
  1. int newSize
)

Sets the receive window size and re-advertises.

Note this cannot revoke credit already granted: what goes on the wire is bytesConsumed + newSize, and the peer applies offsets monotonically. A size smaller than the outstanding grant simply takes effect once the peer catches up to the offset it already holds.

Implementation

void setWindow(int newSize) {
  _receiveWindow = newSize;
  final limit = _bytesConsumed + _receiveWindow;
  if (limit > _lastAdvertised) _lastAdvertised = limit;
  if (_connected && remoteId != null && _socket != null && !_socket!.closing) {
    _socket!.sendStreamPacket(
      remoteId!,
      id,
      // See _onDataConsumed: sent modulo 2^32, reconstructed by the peer.
      [WindowUpdateFrame(windowSize: _lastAdvertised & 0xFFFFFFFF)],
      trackForRetransmit: false,
    );
  }
}