| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -939,7 +939,7 @@ For TCP connections, available `options` are: | |||
| 939 | 939 | * `autoSelectFamilyAttemptTimeout` {number}: The amount of time in milliseconds to wait | |
| 940 | 940 | for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. | |
| 941 | 941 | If set to a positive integer less than `10`, then the value `10` will be used instead. | |
| 942 | - **Default:** `250`. | ||
| 942 | + **Default:** initially `250`, but it can be changed at runtime using [`net.setDefaultAutoSelectFamilyAttemptTimeout(value)`][] | ||
| 943 | 943 | ||
| 944 | 944 | For [IPC][] connections, available `options` are: | |
| 945 | 945 | ||
@@ -1526,26 +1526,6 @@ immediately initiates connection with | |||
| 1526 | 1526 | [`socket.connect(port[, host][, connectListener])`][`socket.connect(port)`], | |
| 1527 | 1527 | then returns the `net.Socket` that starts the connection. | |
| 1528 | 1528 | ||
| 1529 | - ## `net.setDefaultAutoSelectFamily(value)` | ||
| 1530 | - | ||
| 1531 | - <!-- YAML | ||
| 1532 | - added: v19.4.0 | ||
| 1533 | - --> | ||
| 1534 | - | ||
| 1535 | - Sets the default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. | ||
| 1536 | - | ||
| 1537 | - * `value` {boolean} The new default value. The initial default value is `false`. | ||
| 1538 | - | ||
| 1539 | - ## `net.getDefaultAutoSelectFamily()` | ||
| 1540 | - | ||
| 1541 | - <!-- YAML | ||
| 1542 | - added: v19.4.0 | ||
| 1543 | - --> | ||
| 1544 | - | ||
| 1545 | - Gets the current default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. | ||
| 1546 | - | ||
| 1547 | - * Returns: {boolean} The current default value of the `autoSelectFamily` option. | ||
| 1548 | - | ||
| 1549 | 1529 | ## `net.createServer([options][, connectionListener])` | |
| 1550 | 1530 | ||
| 1551 | 1531 | <!-- YAML | |
@@ -1640,6 +1620,47 @@ Use `nc` to connect to a Unix domain socket server: | |||
| 1640 | 1620 | $ nc -U /tmp/echo.sock | |
| 1641 | 1621 | ``` | |
| 1642 | 1622 | ||
| 1623 | + ## `net.getDefaultAutoSelectFamily()` | ||
| 1624 | + | ||
| 1625 | + <!-- YAML | ||
| 1626 | + added: v19.4.0 | ||
| 1627 | + --> | ||
| 1628 | + | ||
| 1629 | + Gets the current default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. | ||
| 1630 | + | ||
| 1631 | + * Returns: {boolean} The current default value of the `autoSelectFamily` option. | ||
| 1632 | + | ||
| 1633 | + ## `net.setDefaultAutoSelectFamily(value)` | ||
| 1634 | + | ||
| 1635 | + <!-- YAML | ||
| 1636 | + added: v19.4.0 | ||
| 1637 | + --> | ||
| 1638 | + | ||
| 1639 | + Sets the default value of the `autoSelectFamily` option of [`socket.connect(options)`][]. | ||
| 1640 | + | ||
| 1641 | + * `value` {boolean} The new default value. The initial default value is `false`. | ||
| 1642 | + | ||
| 1643 | + ## `net.getDefaultAutoSelectFamilyAttemptTimeout()` | ||
| 1644 | + | ||
| 1645 | + <!-- YAML | ||
| 1646 | + added: REPLACEME | ||
| 1647 | + --> | ||
| 1648 | + | ||
| 1649 | + Gets the current default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. | ||
| 1650 | + | ||
| 1651 | + * Returns: {number} The current default value of the `autoSelectFamilyAttemptTimeout` option. | ||
| 1652 | + | ||
| 1653 | + ## `net.setDefaultAutoSelectFamilyAttemptTimeout(value)` | ||
| 1654 | + | ||
| 1655 | + <!-- YAML | ||
| 1656 | + added: REPLACEME | ||
| 1657 | + --> | ||
| 1658 | + | ||
| 1659 | + Sets the default value of the `autoSelectFamilyAttemptTimeout` option of [`socket.connect(options)`][]. | ||
| 1660 | + | ||
| 1661 | + * `value` {number} The new default value, which must be a positive number. If the number is less than `10`, | ||
| 1662 | + the value `10` is used insted The initial default value is `250`. | ||
| 1663 | + | ||
| 1643 | 1664 | ## `net.isIP(input)` | |
| 1644 | 1665 | ||
| 1645 | 1666 | <!-- YAML | |
@@ -1725,6 +1746,7 @@ net.isIPv6('fhqwhgads'); // returns false | |||
| 1725 | 1746 | [`net.createConnection(port, host)`]: #netcreateconnectionport-host-connectlistener | |
| 1726 | 1747 | [`net.createServer()`]: #netcreateserveroptions-connectionlistener | |
| 1727 | 1748 | [`net.setDefaultAutoSelectFamily(value)`]: #netsetdefaultautoselectfamilyvalue | |
| 1749 | + [`net.setDefaultAutoSelectFamilyAttemptTimeout(value)`]: #netsetdefaultautoselectfamilyattempttimeoutvalue | ||
| 1728 | 1750 | [`new net.Socket(options)`]: #new-netsocketoptions | |
| 1729 | 1751 | [`readable.setEncoding()`]: stream.md#readablesetencodingencoding | |
| 1730 | 1752 | [`server.close()`]: #serverclosecallback | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,7 +54,7 @@ const EE = require('events'); | |||
| 54 | 54 | const net = require('net'); | |
| 55 | 55 | const tls = require('tls'); | |
| 56 | 56 | const common = require('_tls_common'); | |
| 57 | - const { kWrapConnectedHandle } = require('internal/net'); | ||
| 57 | + const { kReinitializeHandle } = require('internal/net'); | ||
| 58 | 58 | const JSStreamSocket = require('internal/js_stream_socket'); | |
| 59 | 59 | const { Buffer } = require('buffer'); | |
| 60 | 60 | let debug = require('internal/util/debuglog').debuglog('tls', (fn) => { | |
@@ -633,14 +633,27 @@ TLSSocket.prototype._wrapHandle = function(wrap, handle) { | |||
| 633 | 633 | return res; | |
| 634 | 634 | }; | |
| 635 | 635 | ||
| 636 | - TLSSocket.prototype[kWrapConnectedHandle] = function(handle) { | ||
| 637 | - this._handle = this._wrapHandle(null, handle); | ||
| 636 | + TLSSocket.prototype[kReinitializeHandle] = function reinitializeHandle(handle) { | ||
| 637 | + const originalServername = this._handle.getServername(); | ||
| 638 | + const originalSession = this._handle.getSession(); | ||
| 639 | + | ||
| 640 | + this.handle = this._wrapHandle(null, handle); | ||
| 638 | 641 | this.ssl = this._handle; | |
| 642 | + | ||
| 643 | + net.Socket.prototype[kReinitializeHandle].call(this, this.handle); | ||
| 639 | 644 | this._init(); | |
| 640 | 645 | ||
| 641 | 646 | if (this._tlsOptions.enableTrace) { | |
| 642 | 647 | this._handle.enableTrace(); | |
| 643 | 648 | } | |
| 649 | + | ||
| 650 | + if (originalSession) { | ||
| 651 | + this.setSession(originalSession); | ||
| 652 | + } | ||
| 653 | + | ||
| 654 | + if (originalServername) { | ||
| 655 | + this.setServername(originalServername); | ||
| 656 | + } | ||
| 644 | 657 | }; | |
| 645 | 658 | ||
| 646 | 659 | // This eliminates a cyclic reference to TLSWrap | |
@@ -679,6 +692,30 @@ TLSSocket.prototype._destroySSL = function _destroySSL() { | |||
| 679 | 692 | this[kIsVerified] = false; | |
| 680 | 693 | }; | |
| 681 | 694 | ||
| 695 | + function keylogNewListener(event) { | ||
| 696 | + if (event !== 'keylog') | ||
| 697 | + return; | ||
| 698 | + | ||
| 699 | + // Guard against enableKeylogCallback after destroy | ||
| 700 | + if (!this._handle) return; | ||
| 701 | + this._handle.enableKeylogCallback(); | ||
| 702 | + | ||
| 703 | + // Remove this listener since it's no longer needed. | ||
| 704 | + this.removeListener('newListener', keylogNewListener); | ||
| 705 | + } | ||
| 706 | + | ||
| 707 | + function newListener(event) { | ||
| 708 | + if (event !== 'session') | ||
| 709 | + return; | ||
| 710 | + | ||
| 711 | + // Guard against enableSessionCallbacks after destroy | ||
| 712 | + if (!this._handle) return; | ||
| 713 | + this._handle.enableSessionCallbacks(); | ||
| 714 | + | ||
| 715 | + // Remove this listener since it's no longer needed. | ||
| 716 | + this.removeListener('newListener', newListener); | ||
| 717 | + } | ||
| 718 | + | ||
| 682 | 719 | // Constructor guts, arbitrarily factored out. | |
| 683 | 720 | let warnOnTlsKeylog = true; | |
| 684 | 721 | let warnOnTlsKeylogError = true; | |
@@ -704,18 +741,9 @@ TLSSocket.prototype._init = function(socket, wrap) { | |||
| 704 | 741 | ||
| 705 | 742 | // Only call .onkeylog if there is a keylog listener. | |
| 706 | 743 | ssl.onkeylog = onkeylog; | |
| 707 | - this.on('newListener', keylogNewListener); | ||
| 708 | 744 | ||
| 709 | - function keylogNewListener(event) { | ||
| 710 | - if (event !== 'keylog') | ||
| 711 | - return; | ||
| 712 | - | ||
| 713 | - // Guard against enableKeylogCallback after destroy | ||
| 714 | - if (!this._handle) return; | ||
| 715 | - this._handle.enableKeylogCallback(); | ||
| 716 | - | ||
| 717 | - // Remove this listener since it's no longer needed. | ||
| 718 | - this.removeListener('newListener', keylogNewListener); | ||
| 745 | + if (this.listenerCount('newListener', keylogNewListener) === 0) { | ||
| 746 | + this.on('newListener', keylogNewListener); | ||
| 719 | 747 | } | |
| 720 | 748 | ||
| 721 | 749 | if (options.isServer) { | |
@@ -750,18 +778,8 @@ TLSSocket.prototype._init = function(socket, wrap) { | |||
| 750 | 778 | ssl.onnewsession = onnewsessionclient; | |
| 751 | 779 | ||
| 752 | 780 | // Only call .onnewsession if there is a session listener. | |
| 753 | - this.on('newListener', newListener); | ||
| 754 | - | ||
| 755 | - function newListener(event) { | ||
| 756 | - if (event !== 'session') | ||
| 757 | - return; | ||
| 758 | - | ||
| 759 | - // Guard against enableSessionCallbacks after destroy | ||
| 760 | - if (!this._handle) return; | ||
| 761 | - this._handle.enableSessionCallbacks(); | ||
| 762 | - | ||
| 763 | - // Remove this listener since it's no longer needed. | ||
| 764 | - this.removeListener('newListener', newListener); | ||
| 781 | + if (this.listenerCount('newListener', newListener) === 0) { | ||
| 782 | + this.on('newListener', newListener); | ||
| 765 | 783 | } | |
| 766 | 784 | } | |
| 767 | 785 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -67,7 +67,7 @@ function makeSyncWrite(fd) { | |||
| 67 | 67 | } | |
| 68 | 68 | ||
| 69 | 69 | module.exports = { | |
| 70 | - kWrapConnectedHandle: Symbol('wrapConnectedHandle'), | ||
| 70 | + kReinitializeHandle: Symbol('reinitializeHandle'), | ||
| 71 | 71 | isIP, | |
| 72 | 72 | isIPv4, | |
| 73 | 73 | isIPv6, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments