@@ -297,8 +297,8 @@ const endpointRegistry = new SafeSet();
297297 * (e.g. HTTP/3).
298298 * @property {'high'|'default'|'low' } [priority] The priority level of the stream.
299299 * @property {boolean } [incremental] Whether to interleave data with same-priority streams.
300- * @property {number } [highWaterMark ] The high water mark for write
301- * backpressure, in bytes. **Default:** `65536`.
300+ * @property {number } [budget ] The byte budget for write backpressure.
301+ * **Default:** `65536`.
302302 * @property {OnHeadersCallback } [onheaders] Callback for incoming initial headers
303303 * @property {OnTrailersCallback } [ontrailers] Callback for incoming trailing headers
304304 * @property {OnInfoCallback } [oninfo] Callback for informational (1xx) headers
@@ -1325,7 +1325,7 @@ function applyCallbacks(session, cbs) {
13251325 * @param {QuicStream } stream The JS stream object
13261326 * @param {any } body The body source
13271327 */
1328- const kDefaultHighWaterMark = 65536 ;
1328+ const kDefaultBudget = 65536 ;
13291329const kDefaultMaxPendingDatagrams = 128 ;
13301330
13311331function configureOutbound ( handle , stream , body ) {
@@ -1405,20 +1405,20 @@ function configureOutbound(handle, stream, body) {
14051405 ) ;
14061406}
14071407
1408- // Sets the high water mark and initial writeDesiredSize for a streaming
1408+ // Sets the budget and initial writeDesiredSize for a streaming
14091409// outbound source. Called after handle.initStreamingSource() for both
14101410// body-source and writer paths. One-shot body sources (string, Uint8Array,
14111411// Blob, FileHandle, etc.) do not use this -- they go through attachSource
14121412// and are not subject to backpressure.
14131413function initStreamingBackpressure ( stream ) {
14141414 const state = getQuicStreamState ( stream ) ;
14151415 // Only set defaults if the user hasn't already configured them
1416- // (e.g., via createBidirectionalStream({ highWaterMark : N })).
1417- if ( state . highWaterMark === 0 ) {
1418- state . highWaterMark = kDefaultHighWaterMark ;
1416+ // (e.g., via createBidirectionalStream({ budget : N })).
1417+ if ( state . budget === 0 ) {
1418+ state . budget = kDefaultBudget ;
14191419 }
14201420 if ( state . writeDesiredSize === 0 ) {
1421- state . writeDesiredSize = state . highWaterMark ;
1421+ state . writeDesiredSize = state . budget ;
14221422 }
14231423}
14241424
@@ -1699,23 +1699,23 @@ class QuicStream {
16991699 }
17001700
17011701 /**
1702- * The high water mark for write backpressure. When the total queued
1702+ * The byte budget for write backpressure. When the total queued
17031703 * outbound bytes exceeds this value, writeSync returns false and
1704- * desiredSize drops to 0 . Default is 65536 (64KB).
1704+ * canWrite returns false . Default is 65536 (64KB).
17051705 * @type {number }
17061706 */
1707- get highWaterMark ( ) {
1707+ get budget ( ) {
17081708 assertIsQuicStream ( this ) ;
1709- return this . #inner. state . highWaterMark ;
1709+ return this . #inner. state . budget ;
17101710 }
17111711
1712- set highWaterMark ( val ) {
1712+ set budget ( val ) {
17131713 assertIsQuicStream ( this ) ;
1714- validateInteger ( val , 'highWaterMark ' , 0 , 0xFFFFFFFF ) ;
1714+ validateInteger ( val , 'budget ' , 0 , 0xFFFFFFFF ) ;
17151715 const inner = this . #inner;
1716- inner . state . highWaterMark = val ;
1716+ inner . state . budget = val ;
17171717 // If writeDesiredSize hasn't been set yet (still 0 from initialization),
1718- // initialize it to the highWaterMark so the first write can proceed.
1718+ // initialize it to the budget so the first write can proceed.
17191719 if ( inner . state . writeDesiredSize === 0 && val > 0 ) {
17201720 inner . state . writeDesiredSize = val ;
17211721 }
@@ -2163,8 +2163,8 @@ class QuicStream {
21632163 // will accept the data into the DataQueue and
21642164 // UpdateWriteDesiredSize() will drop writeDesiredSize toward 0,
21652165 // at which point the standard drain mechanism takes over.
2166- // This follows the Web Streams model where writes beyond the HWM
2167- // succeed and backpressure applies to *subsequent* writes.
2166+ // This follows the iter-streams model where writes beyond the
2167+ // budget succeed and backpressure applies to *subsequent* writes.
21682168 if ( stream . #inner. state . writeDesiredSize === 0 ) return false ;
21692169 const result = handle . write ( [ chunk ] ) ;
21702170 if ( result === undefined ) return false ;
@@ -2323,9 +2323,9 @@ class QuicStream {
23232323
23242324 const writer = {
23252325 __proto__ : null ,
2326- get desiredSize ( ) {
2326+ get canWrite ( ) {
23272327 if ( closed || errored || stream . #inner. state . writeEnded ) return null ;
2328- return stream . #inner. state . writeDesiredSize ;
2328+ return stream . #inner. state . writeDesiredSize > 0 ;
23292329 } ,
23302330 writeSync,
23312331 write,
@@ -3254,7 +3254,7 @@ class QuicSession {
32543254 body,
32553255 priority = 'default' ,
32563256 incremental = false ,
3257- highWaterMark = kDefaultHighWaterMark ,
3257+ budget = kDefaultBudget ,
32583258 headers,
32593259 onheaders,
32603260 ontrailers,
@@ -3290,8 +3290,8 @@ class QuicSession {
32903290 stream [ kAttachFileHandle ] ( body ) ;
32913291 }
32923292
3293- // Set the high water mark for backpressure.
3294- stream . highWaterMark = highWaterMark ;
3293+ // Set the byte budget for backpressure.
3294+ stream . budget = budget ;
32953295
32963296 // Set stream callbacks before sending headers to avoid missing events.
32973297 if ( onheaders ) stream . onheaders = onheaders ;
@@ -4047,8 +4047,8 @@ class QuicSession {
40474047 const stream = new QuicStream ( kPrivateConstructor , handle , this , direction ,
40484048 false /* isLocal */ ) ;
40494049
4050- // Set the default high water mark for received streams.
4051- stream . highWaterMark = kDefaultHighWaterMark ;
4050+ // Set the default byte budget for received streams.
4051+ stream . budget = kDefaultBudget ;
40524052
40534053 // A new stream was received. If we don't have an onstream callback, then
40544054 // there's nothing we can do about it. Destroy the stream in this case.
0 commit comments