| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,7 @@ | |||
| 23 | 23 | ||
| 24 | 24 | const { Object, ObjectPrototype } = primordials; | |
| 25 | 25 | ||
| 26 | + const { getDefaultHighWaterMark } = require('internal/streams/state'); | ||
| 26 | 27 | const assert = require('internal/assert'); | |
| 27 | 28 | const Stream = require('stream'); | |
| 28 | 29 | const internalUtil = require('internal/util'); | |
@@ -51,6 +52,7 @@ const { | |||
| 51 | 52 | } = require('internal/errors'); | |
| 52 | 53 | const { validateString } = require('internal/validators'); | |
| 53 | 54 | ||
| 55 | + const HIGH_WATER_MARK = getDefaultHighWaterMark(); | ||
| 54 | 56 | const { CRLF, debug } = common; | |
| 55 | 57 | ||
| 56 | 58 | const kIsCorked = Symbol('isCorked'); | |
@@ -277,7 +279,7 @@ function _writeRaw(data, encoding, callback) { | |||
| 277 | 279 | this.outputData.push({ data, encoding, callback }); | |
| 278 | 280 | this.outputSize += data.length; | |
| 279 | 281 | this._onPendingData(data.length); | |
| 280 | - return false; | ||
| 282 | + return this.outputSize < HIGH_WATER_MARK; | ||
| 281 | 283 | } | |
| 282 | 284 | ||
| 283 | 285 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,10 @@ function highWaterMarkFrom(options, isDuplex, duplexKey) { | |||
| 9 | 9 | isDuplex ? options[duplexKey] : null; | |
| 10 | 10 | } | |
| 11 | 11 | ||
| 12 | + function getDefaultHighWaterMark(objectMode) { | ||
| 13 | + return objectMode ? 16 : 16 * 1024; | ||
| 14 | + } | ||
| 15 | + | ||
| 12 | 16 | function getHighWaterMark(state, options, duplexKey, isDuplex) { | |
| 13 | 17 | const hwm = highWaterMarkFrom(options, isDuplex, duplexKey); | |
| 14 | 18 | if (hwm != null) { | |
@@ -20,9 +24,10 @@ function getHighWaterMark(state, options, duplexKey, isDuplex) { | |||
| 20 | 24 | } | |
| 21 | 25 | ||
| 22 | 26 | // Default value | |
| 23 | - return state.objectMode ? 16 : 16 * 1024; | ||
| 27 | + return getDefaultHighWaterMark(state.objectMode); | ||
| 24 | 28 | } | |
| 25 | 29 | ||
| 26 | 30 | module.exports = { | |
| 27 | - getHighWaterMark | ||
| 31 | + getHighWaterMark, | ||
| 32 | + getDefaultHighWaterMark | ||
| 28 | 33 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,19 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + const { getDefaultHighWaterMark } = require('internal/streams/state'); | ||
| 6 | + | ||
| 7 | + const http = require('http'); | ||
| 8 | + const OutgoingMessage = http.OutgoingMessage; | ||
| 9 | + | ||
| 10 | + const msg = new OutgoingMessage(); | ||
| 11 | + msg._implicitHeader = function() {}; | ||
| 12 | + | ||
| 13 | + // Writes should be buffered until highwatermark | ||
| 14 | + // even when no socket is assigned. | ||
| 15 | + | ||
| 16 | + assert.strictEqual(msg.write('asd'), true); | ||
| 17 | + while (msg.write('asd')); | ||
| 18 | + const highwatermark = msg.writableHighWaterMark || getDefaultHighWaterMark(); | ||
| 19 | + assert(msg.outputSize >= highwatermark); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments