From 159f874f1f01529510754c1124523cd8ba7dcb8e Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Mon, 4 Dec 2023 16:46:49 +0100 Subject: [PATCH] net: add connection attempt events --- 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'`