From e4be5b60f0ea6366866e6b4d5a8b8087943a9e11 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Thu, 21 Dec 2023 11:43:15 +0100 Subject: [PATCH] net: add connection attempt events PR-URL: https://github.com/nodejs/node/pull/51045 Fixes: https://github.com/nodejs/node/issues/48763 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Marco Ippolito --- doc/api/net.md | 44 ++- lib/net.js | 31 +- test/common/dns.js | 21 + ...est-net-autoselectfamily-events-failure.js | 128 ++++++ ...est-net-autoselectfamily-events-timeout.js | 54 +++ ...test-net-autoselectfamily-timeout-close.js | 9 + ...net-autoselectfamily-commandline-option.js | 116 ++---- .../test-net-autoselectfamily-default.js | 169 +++----- .../test-net-autoselectfamily-ipv4first.js | 117 ++---- test/parallel/test-net-autoselectfamily.js | 374 +++++++----------- 10 files changed, 549 insertions(+), 514 deletions(-) create mode 100644 test/internet/test-net-autoselectfamily-events-failure.js create mode 100644 test/internet/test-net-autoselectfamily-events-timeout.js diff --git a/doc/api/net.md b/doc/api/net.md index fc260b9f636266..8a66a0a68b4c60 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -691,6 +691,47 @@ added: v0.1.90 Emitted when a socket connection is successfully established. See [`net.createConnection()`][]. +### Event: `'connectionAttempt'` + + + +* `ip` {number} The IP which the socket is attempting to connect to. +* `port` {number} The port which the socket is attempting to connect to. +* `family` {number} The family of the IP. It can be `6` for IPv6 or `4` for IPv4. + +Emitted when a new connection attempt is started. This may be emitted multiple times +if the family autoselection algorithm is enabled in [`socket.connect(options)`][]. + +### Event: `'connectionAttemptFailed'` + + + +* `ip` {number} The IP which the socket attempted to connect to. +* `port` {number} The port which the socket attempted to connect to. +* `family` {number} The family of the IP. It can be `6` for IPv6 or `4` for IPv4. + \* `error` {Error} The error associated with the failure. + +Emitted when a connection attempt failed. This may be emitted multiple times +if the family autoselection algorithm is enabled in [`socket.connect(options)`][]. + +### Event: `'connectionAttemptTimeout'` + + + +* `ip` {number} The IP which the socket attempted to connect to. +* `port` {number} The port which the socket attempted to connect to. +* `family` {number} The family of the IP. It can be `6` for IPv6 or `4` for IPv4. + +Emitted when a connection attempt timed out. This is only emitted (and may be +emitted multiple times) if the family autoselection algorithm is enabled +in [`socket.connect(options)`][]. + ### Event: `'data'`