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 <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • 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.