| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 152c931 commit 5b12d3a
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,7 @@ const { async_id_symbol } = process.binding('async_wrap'); | |||
| 50 | 50 | const { newUid, defaultTriggerAsyncIdScope } = require('internal/async_hooks'); | |
| 51 | 51 | const { nextTick } = require('internal/process/next_tick'); | |
| 52 | 52 | const errors = require('internal/errors'); | |
| 53 | + const DuplexBase = require('internal/streams/duplex_base'); | ||
| 53 | 54 | const dns = require('dns'); | |
| 54 | 55 | ||
| 55 | 56 | const kLastWriteQueueSize = Symbol('lastWriteQueueSize'); | |
@@ -211,7 +212,11 @@ function Socket(options) { | |||
| 211 | 212 | else if (options === undefined) | |
| 212 | 213 | options = {}; | |
| 213 | 214 | ||
| 214 | - stream.Duplex.call(this, options); | ||
| 215 | + // `DuplexBase` is just a slimmed down constructor for `Duplex` which allow | ||
| 216 | + // us to not inherit the "no-half-open enforcer" as there is already one in | ||
| 217 | + // place. Instances of `Socket` are still instances of `Duplex`, that is, | ||
| 218 | + // `socket instanceof Duplex === true`. | ||
| 219 | + DuplexBase.call(this, options); | ||
| 215 | 220 | ||
| 216 | 221 | if (options.handle) { | |
| 217 | 222 | this._handle = options.handle; // private | |
@@ -236,8 +241,6 @@ function Socket(options) { | |||
| 236 | 241 | this._writev = null; | |
| 237 | 242 | this._write = makeSyncWrite(fd); | |
| 238 | 243 | } | |
| 239 | - this.readable = options.readable !== false; | ||
| 240 | - this.writable = options.writable !== false; | ||
| 241 | 244 | } else { | |
| 242 | 245 | // these will be set once there is a connection | |
| 243 | 246 | this.readable = this.writable = false; | |
@@ -256,7 +259,7 @@ function Socket(options) { | |||
| 256 | 259 | this._writableState.decodeStrings = false; | |
| 257 | 260 | ||
| 258 | 261 | // default to *not* allowing half open sockets | |
| 259 | - this.allowHalfOpen = options && options.allowHalfOpen || false; | ||
| 262 | + this.allowHalfOpen = options.allowHalfOpen || false; | ||
| 260 | 263 | ||
| 261 | 264 | // if we have a handle, then start the flow of data into the | |
| 262 | 265 | // buffer. if not, then this will happen when we connect | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,12 +68,7 @@ server.listen(0, common.mustCall(() => { | |||
| 68 | 68 | assert.strictEqual(socket.listeners('connect').length, 0); | |
| 69 | 69 | assert.strictEqual(socket.listeners('data').length, 0); | |
| 70 | 70 | assert.strictEqual(socket.listeners('drain').length, 0); | |
| 71 | - | ||
| 72 | - // the stream.Duplex onend listener | ||
| 73 | - // allow 0 here, so that i can run the same test on streams1 impl | ||
| 74 | - assert(socket.listenerCount('end') <= 2, | ||
| 75 | - `Found ${socket.listenerCount('end')} end listeners`); | ||
| 76 | - | ||
| 71 | + assert.strictEqual(socket.listeners('end').length, 1); | ||
| 77 | 72 | assert.strictEqual(socket.listeners('free').length, 0); | |
| 78 | 73 | assert.strictEqual(socket.listeners('close').length, 0); | |
| 79 | 74 | assert.strictEqual(socket.listeners('error').length, 0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,11 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + | ||
| 4 | + // This test ensures that `net.Socket` does not inherit the no-half-open | ||
| 5 | + // enforcer from `stream.Duplex`. | ||
| 6 | + | ||
| 7 | + const { Socket } = require('net'); | ||
| 8 | + const { strictEqual } = require('assert'); | ||
| 9 | + | ||
| 10 | + const socket = new Socket({ allowHalfOpen: false }); | ||
| 11 | + strictEqual(socket.listenerCount('end'), 1); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments