Skip to content

Commit

Permalink
lib: return this from net.Socket.end()
Browse files Browse the repository at this point in the history
PR-URL: #13481
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Brian White <mscdex@mscdex.net>
  • Loading branch information
sam-github authored and jasnell committed Jun 7, 2017
1 parent 71a3d2c commit 4b2c756
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ server will still send some data.
If `data` is specified, it is equivalent to calling
`socket.write(data, encoding)` followed by [`socket.end()`][].

Returns `socket`.

### socket.localAddress
<!-- YAML
added: v0.9.6
Expand Down
2 changes: 2 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ Socket.prototype.end = function(data, encoding) {
this.read(0);
else
maybeDestroy(this);

return this;
};


Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-socket-write-after-fin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const common = require('../common');
const assert = require('assert');
const net = require('net');
const expected = 'hello1hello2hello3\nTHUNDERMUSCLE!';
const expected = 'hello1hello2hello3\nbye';

const server = net.createServer({
allowHalfOpen: true
Expand Down Expand Up @@ -35,5 +35,6 @@ server.listen(0, common.mustCall(function() {
sock.write('hello1');
sock.write('hello2');
sock.write('hello3\n');
sock.end('THUNDERMUSCLE!');
assert.strictEqual(sock.end('bye'), sock);

}));

0 comments on commit 4b2c756

Please sign in to comment.