open method

Future<void> open()

Opens the stream (called by session when creating a new stream locally or accepting one)

Implementation

Future<void> open() async {
  _log.finer('$_logPrefix open() called. Current state: $_state');
  if (_state != YamuxStreamState.init) {
    _log.warning('$_logPrefix open() called on stream not in init state: $_state');
    throw StateError('Stream is not in init state');
  }
  // Note: Yamux doesn't have an explicit "open" frame like SYN.
  // For an outbound stream, sending the first DATA frame effectively opens it.
  // For an inbound stream, receiving the first DATA frame opens it.
  // The session handles sending initial window updates when it establishes the stream.
  _state = YamuxStreamState.open;
  _log.fine('$_logPrefix Stream opened. State: $_state. Sending initial window update.');

  // Send initial window update to the remote peer
  final frame = YamuxFrame.windowUpdate(streamId, _localReceiveWindow);
  await _sendFrame(frame);
}