Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
net: simplify net.Socket#end()
`writable` is already set by the streams side, and
there is a handler waiting for the writable side to finish
which already takes care of the other cleanup code that
was previously there; both of these things can therefore be removed.
  • Loading branch information
addaleax committed Feb 11, 2018
commit 4bb7b4be859d2a01732f33aebdd0f29fd7fbcae3
8 changes: 0 additions & 8 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,16 +524,8 @@ Socket.prototype._read = function(n) {

Socket.prototype.end = function(data, encoding) {
stream.Duplex.prototype.end.call(this, data, encoding);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we are at it, can you add a callback to end()? that's the full signature for streams (https://nodejs.org/api/stream.html#stream_writable_end_chunk_encoding_callback).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, done!

this.writable = false;
DTRACE_NET_STREAM_END(this);
LTTNG_NET_STREAM_END(this);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move these to _destroy instead and use a stock end implementation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think would be a breaking change in light of your comment about not returning this below :/ I’d agree that that would be ideal, definitely.


// just in case we're waiting for an EOF.
if (this.readable && !this._readableState.endEmitted)
this.read(0);
else
maybeDestroy(this);

return this;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, this differs from node streams, as end  does not return this. We might want to add it to streams too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll send a follow up PR to this one, which will be a semver-major.

};

Expand Down