closeWrite method
Implementation
Future<void> closeWrite() async {
if (_localWriteClosed) return;
_localWriteClosed = true;
if (!_connected || remoteId == null || _socket == null || _socket!.closing) return;
// Send FIN via socket
_socket!.sendStreamPacket(
remoteId!,
id,
// A FIN carries no data, so its offset is this stream's final size. The
// peer needs that to know when it has everything: a FIN can overtake data
// still in flight, and treating its arrival as the end would truncate the
// tail.
[StreamFrame(data: Uint8List(0), isFin: true, offset: bytesWritten)],
);
// Small delay to ensure FIN is sent
await Future.delayed(Duration(milliseconds: 50));
if (_remoteWriteClosed) {
await _close();
}
}