Skip to content

Commit

Permalink
lib: fix return type of setTimeout in net.Socket
Browse files Browse the repository at this point in the history
Function setTimeout in net.Socket should return this,
not undefined, as doc said.

PR-URL: #32722
Refs: https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Zeyu Yang <[email protected]>
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
LongTengDao authored and targos committed Apr 12, 2020
1 parent 1a01ac3 commit 23e56ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/internal/stream_base_commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function onStreamRead(arrayBuffer) {

function setStreamTimeout(msecs, callback) {
if (this.destroyed)
return;
return this;

this.timeout = msecs;

Expand Down
12 changes: 8 additions & 4 deletions test/parallel/test-net-socket-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,12 @@ for (let i = 0; i < invalidCallbacks.length; i++) {
const server = net.Server();
server.listen(0, common.mustCall(() => {
const socket = net.createConnection(server.address().port);
socket.setTimeout(1, common.mustCall(() => {
socket.destroy();
server.close();
}));
assert.strictEqual(
socket.setTimeout(1, common.mustCall(() => {
socket.destroy();
assert.strictEqual(socket.setTimeout(1, common.mustNotCall()), socket);
server.close();
})),
socket
);
}));

0 comments on commit 23e56ff

Please sign in to comment.