中止流


🌐 Aborting a stream

QuicStream 可以通过几种方式中止,每种方式都会产生不同的网络帧副作用:

🌐 A QuicStream can be aborted in several ways, each producing different wire-frame side effects:

  • stream.stopSending() — 只中止可读端。向对端发送 STOP_SENDING。可写端不受影响。
  • stream.resetStream() — 仅中止可写的一侧。向对端发送 RESET_STREAM。与 writer.fail(reason) 不同的是,线编码是直接给出的,而不是从错误中派生出来的。
  • writer.fail(reason) — 仅中止可写的一侧。向对端发送 RESET_STREAM。可读的一侧不受影响;任何已经缓冲的可读数据仍然可用。
  • stream.destroy() 使用 error 参数 — 完全中断流。向任何仍然打开的可写端发送 RESET_STREAM,并向任何仍然打开的可读端发送 STOP_SENDING。该线代码源自 error(优先规则见 stream.destroy())。
  • stream.destroy() 带有一个显式的 options.code — 与之前的形式相同,但使用调用者提供的线路代码,该代码优先于 error 所携带的任何代码。

当 error 是 QuicError 时,其 error.errorCode 用作 writer.fail() 和 stream.destroy() 的线码。否则,实现将回退到协商的应用协议的“内部错误”代码(参见 QuicError)。

🌐 When error is a QuicError, its error.errorCode is used as the wire code for both writer.fail() and stream.destroy(). Otherwise the implementation falls back to the negotiated application protocol's "internal error" code (see QuicError).

stream.stopSending() 和 stream.resetStream() 不执行这个推导:它们直接发送 code。