| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f321921 commit edb9846
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -437,6 +437,14 @@ process.nextTick(() => { | |||
| 437 | 437 | ||
| 438 | 438 | See also: [`writable.cork()`][]. | |
| 439 | 439 | ||
| 440 | + ##### writable.writableHighWaterMark | ||
| 441 | + <!-- YAML | ||
| 442 | + added: REPLACEME | ||
| 443 | + --> | ||
| 444 | + | ||
| 445 | + Return the value of `highWaterMark` passed when constructing this | ||
| 446 | + `Writable`. | ||
| 447 | + | ||
| 440 | 448 | ##### writable.write(chunk[, encoding][, callback]) | |
| 441 | 449 | <!-- YAML | |
| 442 | 450 | added: v0.9.4 | |
@@ -879,6 +887,14 @@ to prevent memory leaks. | |||
| 879 | 887 | never closed until the Node.js process exits, regardless of the specified | |
| 880 | 888 | options. | |
| 881 | 889 | ||
| 890 | + ##### readable.readableHighWaterMark | ||
| 891 | + <!-- YAML | ||
| 892 | + added: REPLACEME | ||
| 893 | + --> | ||
| 894 | + | ||
| 895 | + Return the value of `highWaterMark` passed when constructing this | ||
| 896 | + `Readable`. | ||
| 897 | + | ||
| 882 | 898 | ##### readable.read([size]) | |
| 883 | 899 | <!-- YAML | |
| 884 | 900 | added: v0.9.4 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -373,13 +373,13 @@ function connectionListener(socket) { | |||
| 373 | 373 | function updateOutgoingData(socket, state, delta) { | |
| 374 | 374 | state.outgoingData += delta; | |
| 375 | 375 | if (socket._paused && | |
| 376 | - state.outgoingData < socket._writableState.highWaterMark) { | ||
| 376 | + state.outgoingData < socket.writeHWM) { | ||
| 377 | 377 | return socketOnDrain(socket, state); | |
| 378 | 378 | } | |
| 379 | 379 | } | |
| 380 | 380 | ||
| 381 | 381 | function socketOnDrain(socket, state) { | |
| 382 | - var needPause = state.outgoingData > socket._writableState.highWaterMark; | ||
| 382 | + var needPause = state.outgoingData > socket.writeHWM; | ||
| 383 | 383 | ||
| 384 | 384 | // If we previously paused, then start reading again. | |
| 385 | 385 | if (socket._paused && !needPause) { | |
@@ -569,7 +569,7 @@ function parserOnIncoming(server, socket, state, req, keepAlive) { | |||
| 569 | 569 | // pipelined requests that may never be resolved. | |
| 570 | 570 | if (!socket._paused) { | |
| 571 | 571 | var ws = socket._writableState; | |
| 572 | - if (ws.needDrain || state.outgoingData >= ws.highWaterMark) { | ||
| 572 | + if (ws.needDrain || state.outgoingData >= socket.writableHighWaterMark) { | ||
| 573 | 573 | socket._paused = true; | |
| 574 | 574 | // We also need to pause the parser, but don't do that until after | |
| 575 | 575 | // the call to execute, because we may still be processing the last | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,11 +34,14 @@ const Writable = require('_stream_writable'); | |||
| 34 | 34 | ||
| 35 | 35 | util.inherits(Duplex, Readable); | |
| 36 | 36 | ||
| 37 | - var keys = Object.keys(Writable.prototype); | ||
| 38 | - for (var v = 0; v < keys.length; v++) { | ||
| 39 | - var method = keys[v]; | ||
| 40 | - if (!Duplex.prototype[method]) | ||
| 41 | - Duplex.prototype[method] = Writable.prototype[method]; | ||
| 37 | + { | ||
| 38 | + // avoid scope creep, the keys array can then be collected | ||
| 39 | + const keys = Object.keys(Writable.prototype); | ||
| 40 | + for (var v = 0; v < keys.length; v++) { | ||
| 41 | + const method = keys[v]; | ||
| 42 | + if (!Duplex.prototype[method]) | ||
| 43 | + Duplex.prototype[method] = Writable.prototype[method]; | ||
| 44 | + } | ||
| 42 | 45 | } | |
| 43 | 46 | ||
| 44 | 47 | function Duplex(options) { | |
@@ -61,6 +64,16 @@ function Duplex(options) { | |||
| 61 | 64 | this.once('end', onend); | |
| 62 | 65 | } | |
| 63 | 66 | ||
| 67 | + Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { | ||
| 68 | + // making it explicit this property is not enumerable | ||
| 69 | + // because otherwise some prototype manipulation in | ||
| 70 | + // userland will fail | ||
| 71 | + enumerable: false, | ||
| 72 | + get: function() { | ||
| 73 | + return this._writableState.highWaterMark; | ||
| 74 | + } | ||
| 75 | + }); | ||
| 76 | + | ||
| 64 | 77 | // the no-half-open enforcer | |
| 65 | 78 | function onend() { | |
| 66 | 79 | // if we allow half-open state, or if the writable side ended, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -916,6 +916,15 @@ Readable.prototype.wrap = function(stream) { | |||
| 916 | 916 | return self; | |
| 917 | 917 | }; | |
| 918 | 918 | ||
| 919 | + Object.defineProperty(Readable.prototype, 'readableHighWaterMark', { | ||
| 920 | + // making it explicit this property is not enumerable | ||
| 921 | + // because otherwise some prototype manipulation in | ||
| 922 | + // userland will fail | ||
| 923 | + enumerable: false, | ||
| 924 | + get: function() { | ||
| 925 | + return this._readableState.highWaterMark; | ||
| 926 | + } | ||
| 927 | + }); | ||
| 919 | 928 | ||
| 920 | 929 | // exposed for testing purposes only. | |
| 921 | 930 | Readable._fromList = fromList; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -334,6 +334,16 @@ function decodeChunk(state, chunk, encoding) { | |||
| 334 | 334 | return chunk; | |
| 335 | 335 | } | |
| 336 | 336 | ||
| 337 | + Object.defineProperty(Writable.prototype, 'writableHighWaterMark', { | ||
| 338 | + // making it explicit this property is not enumerable | ||
| 339 | + // because otherwise some prototype manipulation in | ||
| 340 | + // userland will fail | ||
| 341 | + enumerable: false, | ||
| 342 | + get: function() { | ||
| 343 | + return this._writableState.highWaterMark; | ||
| 344 | + } | ||
| 345 | + }); | ||
| 346 | + | ||
| 337 | 347 | // if we're already writing something, then just put this | |
| 338 | 348 | // in the queue, and wait our turn. Otherwise, call _write | |
| 339 | 349 | // If we return false, then we need a drain event, so set that flag. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2072,7 +2072,7 @@ ReadStream.prototype._read = function(n) { | |||
| 2072 | 2072 | ||
| 2073 | 2073 | if (!pool || pool.length - pool.used < kMinPoolSpace) { | |
| 2074 | 2074 | // discard the old pool. | |
| 2075 | - allocNewPool(this._readableState.highWaterMark); | ||
| 2075 | + allocNewPool(this.readableHighWaterMark); | ||
| 2076 | 2076 | } | |
| 2077 | 2077 | ||
| 2078 | 2078 | // Grab another reference to the pool in the case that while we're | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ const server = http.createServer(function(req, res) { | |||
| 30 | 30 | res.end(chunk); | |
| 31 | 31 | } | |
| 32 | 32 | size += res.outputSize; | |
| 33 | - if (size <= req.socket._writableState.highWaterMark) { | ||
| 33 | + if (size <= req.socket.writableHighWaterMark) { | ||
| 34 | 34 | more(); | |
| 35 | 35 | return; | |
| 36 | 36 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,7 @@ s1.pipe(s3); | |||
| 44 | 44 | s2.pipe(s3, { end: false }); | |
| 45 | 45 | ||
| 46 | 46 | // We must write a buffer larger than highWaterMark | |
| 47 | - const big = Buffer.alloc(s1._writableState.highWaterMark + 1, 'x'); | ||
| 47 | + const big = Buffer.alloc(s1.writableHighWaterMark + 1, 'x'); | ||
| 48 | 48 | ||
| 49 | 49 | // Since big is larger than highWaterMark, it will be buffered internally. | |
| 50 | 50 | assert(!s1.write(big)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,7 +68,7 @@ flow(stream, 5000, function() { | |||
| 68 | 68 | process.on('exit', function(code) { | |
| 69 | 69 | assert.strictEqual(reads, 2); | |
| 70 | 70 | // we pushed up the high water mark | |
| 71 | - assert.strictEqual(stream._readableState.highWaterMark, 8192); | ||
| 71 | + assert.strictEqual(stream.readableHighWaterMark, 8192); | ||
| 72 | 72 | // length is 0 right now, because we pulled it all out. | |
| 73 | 73 | assert.strictEqual(stream._readableState.length, 0); | |
| 74 | 74 | assert(!code); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,8 +29,12 @@ const parser = new Transform({ readableObjectMode: true }); | |||
| 29 | 29 | ||
| 30 | 30 | assert(parser._readableState.objectMode); | |
| 31 | 31 | assert(!parser._writableState.objectMode); | |
| 32 | - assert.strictEqual(parser._readableState.highWaterMark, 16); | ||
| 33 | - assert.strictEqual(parser._writableState.highWaterMark, 16 * 1024); | ||
| 32 | + assert.strictEqual(parser.readableHighWaterMark, 16); | ||
| 33 | + assert.strictEqual(parser.writableHighWaterMark, 16 * 1024); | ||
| 34 | + assert.strictEqual(parser.readableHighWaterMark, | ||
| 35 | + parser._readableState.highWaterMark); | ||
| 36 | + assert.strictEqual(parser.writableHighWaterMark, | ||
| 37 | + parser._writableState.highWaterMark); | ||
| 34 | 38 | ||
| 35 | 39 | parser._transform = function(chunk, enc, callback) { | |
| 36 | 40 | callback(null, { val: chunk[0] }); | |
@@ -53,8 +57,12 @@ const serializer = new Transform({ writableObjectMode: true }); | |||
| 53 | 57 | ||
| 54 | 58 | assert(!serializer._readableState.objectMode); | |
| 55 | 59 | assert(serializer._writableState.objectMode); | |
| 56 | - assert.strictEqual(serializer._readableState.highWaterMark, 16 * 1024); | ||
| 57 | - assert.strictEqual(serializer._writableState.highWaterMark, 16); | ||
| 60 | + assert.strictEqual(serializer.readableHighWaterMark, 16 * 1024); | ||
| 61 | + assert.strictEqual(serializer.writableHighWaterMark, 16); | ||
| 62 | + assert.strictEqual(parser.readableHighWaterMark, | ||
| 63 | + parser._readableState.highWaterMark); | ||
| 64 | + assert.strictEqual(parser.writableHighWaterMark, | ||
| 65 | + parser._writableState.highWaterMark); | ||
| 58 | 66 | ||
| 59 | 67 | serializer._transform = function(obj, _, callback) { | |
| 60 | 68 | callback(null, Buffer.from([obj.val])); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments