Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2018-02-07 01:00:15 +0300
committerMyles Borins <mylesborins@google.com>2018-03-07 20:36:52 +0300
commitef4714c2b649a14768d57384437546dd160f411c (patch)
treeb76efc13bfcae425d021951d6e9b815d4d8e0829
parent1fadb2edb48d227c5e5c18208240dceeb86ccc34 (diff)
net: inline and simplify onSocketEnd
Backport-PR-URL: https://github.com/nodejs/node/pull/19194 PR-URL: https://github.com/nodejs/node/pull/18607 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--lib/net.js41
-rw-r--r--test/parallel/test-http-connect.js3
2 files changed, 13 insertions, 31 deletions
diff --git a/lib/net.js b/lib/net.js
index 09ad917ad0b..90e0db558e3 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -245,7 +245,7 @@ function Socket(options) {
// shut down the socket when we're finished with it.
this.on('finish', onSocketFinish);
- this.on('_socketEnd', onSocketEnd);
+ this.on('end', onReadableStreamEnd);
initSocketHandle(this);
@@ -341,32 +341,6 @@ function afterShutdown(status, handle) {
}
}
-// the EOF has been received, and no more bytes are coming.
-// if the writable side has ended already, then clean everything
-// up.
-function onSocketEnd() {
- // XXX Should not have to do as much in this function.
- // ended should already be true, since this is called *after*
- // the EOF errno and onread has eof'ed
- debug('onSocketEnd', this._readableState);
- this._readableState.ended = true;
- if (this._readableState.endEmitted) {
- this.readable = false;
- maybeDestroy(this);
- } else {
- this.once('end', function end() {
- this.readable = false;
- maybeDestroy(this);
- });
- this.read(0);
- }
-
- if (!this.allowHalfOpen) {
- this.write = writeAfterFIN;
- this.destroySoon();
- }
-}
-
// Provide a better error message when we call end() as a result
// of the other side sending a FIN. The standard 'write after end'
// is overly vague, and makes it seem like the user's code is to blame.
@@ -512,6 +486,12 @@ Socket.prototype.end = function(data, encoding, callback) {
};
+// Called when the 'end' event is emitted.
+function onReadableStreamEnd() {
+ maybeDestroy(this);
+}
+
+
// Call whenever we set writable=false or readable=false
function maybeDestroy(socket) {
if (!socket.readable &&
@@ -625,10 +605,11 @@ function onread(nread, buffer) {
// Do it before `maybeDestroy` for correct order of events:
// `end` -> `close`
self.push(null);
+ self.read(0);
- if (self.readableLength === 0) {
- self.readable = false;
- maybeDestroy(self);
+ if (!self.allowHalfOpen) {
+ self.write = writeAfterFIN;
+ self.destroySoon();
}
// internal end event so that we know that the actual socket
diff --git a/test/parallel/test-http-connect.js b/test/parallel/test-http-connect.js
index 9499cd95275..9b7432f03a7 100644
--- a/test/parallel/test-http-connect.js
+++ b/test/parallel/test-http-connect.js
@@ -71,7 +71,8 @@ server.listen(0, common.mustCall(() => {
// the stream.Duplex onend listener
// allow 0 here, so that i can run the same test on streams1 impl
- assert(socket.listeners('end').length <= 1);
+ assert(socket.listenerCount('end') <= 2,
+ `Found ${socket.listenerCount('end')} end listeners`);
assert.strictEqual(socket.listeners('free').length, 0);
assert.strictEqual(socket.listeners('close').length, 0);