| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent fb6753c commit cbbe95e
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -400,6 +400,12 @@ The `connectListener` parameter will be added as a listener for the | |||
| 400 | 400 | As [`socket.connect(options\[, connectListener\])`][`socket.connect(options, connectListener)`], | |
| 401 | 401 | with options either as either `{port: port, host: host}` or `{path: path}`. | |
| 402 | 402 | ||
| 403 | + ### socket.connecting | ||
| 404 | + | ||
| 405 | + If `true` - [`socket.connect(options\[, connectListener\])`][] was called and | ||
| 406 | + haven't yet finished. Will be set to `false` before emitting `connect` event | ||
| 407 | + and/or calling [`socket.connect(options\[, connectListener\])`][]'s callback. | ||
| 408 | + | ||
| 403 | 409 | ### socket.destroy() | |
| 404 | 410 | ||
| 405 | 411 | Ensures that no more I/O activity happens on this socket. Only necessary in | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -477,7 +477,7 @@ CryptoStream.prototype._done = function() { | |||
| 477 | 477 | // readyState is deprecated. Don't use it. | |
| 478 | 478 | Object.defineProperty(CryptoStream.prototype, 'readyState', { | |
| 479 | 479 | get: function() { | |
| 480 | - if (this._connecting) { | ||
| 480 | + if (this.connecting) { | ||
| 481 | 481 | return 'opening'; | |
| 482 | 482 | } else if (this.readable && this.writable) { | |
| 483 | 483 | return 'open'; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -272,7 +272,7 @@ function TLSSocket(socket, options) { | |||
| 272 | 272 | ||
| 273 | 273 | this._init(socket, wrap); | |
| 274 | 274 | ||
| 275 | - // Make sure to setup all required properties like: `_connecting` before | ||
| 275 | + // Make sure to setup all required properties like: `connecting` before | ||
| 276 | 276 | // starting the flow of the data | |
| 277 | 277 | this.readable = true; | |
| 278 | 278 | this.writable = true; | |
@@ -466,9 +466,9 @@ TLSSocket.prototype._init = function(socket, wrap) { | |||
| 466 | 466 | this._parent = socket; | |
| 467 | 467 | ||
| 468 | 468 | // To prevent assertion in afterConnect() and properly kick off readStart | |
| 469 | - this._connecting = socket._connecting || !socket._handle; | ||
| 469 | + this.connecting = socket.connecting || !socket._handle; | ||
| 470 | 470 | socket.once('connect', function() { | |
| 471 | - self._connecting = false; | ||
| 471 | + self.connecting = false; | ||
| 472 | 472 | self.emit('connect'); | |
| 473 | 473 | }); | |
| 474 | 474 | } | |
@@ -480,7 +480,7 @@ TLSSocket.prototype._init = function(socket, wrap) { | |||
| 480 | 480 | }); | |
| 481 | 481 | } else { | |
| 482 | 482 | assert(!socket); | |
| 483 | - this._connecting = true; | ||
| 483 | + this.connecting = true; | ||
| 484 | 484 | } | |
| 485 | 485 | }; | |
| 486 | 486 | ||
@@ -581,7 +581,7 @@ TLSSocket.prototype._finishInit = function() { | |||
| 581 | 581 | }; | |
| 582 | 582 | ||
| 583 | 583 | TLSSocket.prototype._start = function() { | |
| 584 | - if (this._connecting) { | ||
| 584 | + if (this.connecting) { | ||
| 585 | 585 | this.once('connect', function() { | |
| 586 | 586 | this._start(); | |
| 587 | 587 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -119,7 +119,7 @@ const BYTES_READ = Symbol('bytesRead'); | |||
| 119 | 119 | function Socket(options) { | |
| 120 | 120 | if (!(this instanceof Socket)) return new Socket(options); | |
| 121 | 121 | ||
| 122 | - this._connecting = false; | ||
| 122 | + this.connecting = false; | ||
| 123 | 123 | this._hadError = false; | |
| 124 | 124 | this._handle = null; | |
| 125 | 125 | this._parent = null; | |
@@ -202,7 +202,7 @@ Socket.prototype._unrefTimer = function unrefTimer() { | |||
| 202 | 202 | // so that only the writable side will be cleaned up. | |
| 203 | 203 | function onSocketFinish() { | |
| 204 | 204 | // If still connecting - defer handling 'finish' until 'connect' will happen | |
| 205 | - if (this._connecting) { | ||
| 205 | + if (this.connecting) { | ||
| 206 | 206 | debug('osF: not yet connected'); | |
| 207 | 207 | return this.once('connect', onSocketFinish); | |
| 208 | 208 | } | |
@@ -367,9 +367,16 @@ Socket.prototype.address = function() { | |||
| 367 | 367 | }; | |
| 368 | 368 | ||
| 369 | 369 | ||
| 370 | + Object.defineProperty(Socket.prototype, '_connecting', { | ||
| 371 | + get: function() { | ||
| 372 | + return this.connecting; | ||
| 373 | + } | ||
| 374 | + }); | ||
| 375 | + | ||
| 376 | + | ||
| 370 | 377 | Object.defineProperty(Socket.prototype, 'readyState', { | |
| 371 | 378 | get: function() { | |
| 372 | - if (this._connecting) { | ||
| 379 | + if (this.connecting) { | ||
| 373 | 380 | return 'opening'; | |
| 374 | 381 | } else if (this.readable && this.writable) { | |
| 375 | 382 | return 'open'; | |
@@ -397,7 +404,7 @@ Object.defineProperty(Socket.prototype, 'bufferSize', { | |||
| 397 | 404 | Socket.prototype._read = function(n) { | |
| 398 | 405 | debug('_read'); | |
| 399 | 406 | ||
| 400 | - if (this._connecting || !this._handle) { | ||
| 407 | + if (this.connecting || !this._handle) { | ||
| 401 | 408 | debug('_read wait for connection'); | |
| 402 | 409 | this.once('connect', () => this._read(n)); | |
| 403 | 410 | } else if (!this._handle.reading) { | |
@@ -430,7 +437,7 @@ function maybeDestroy(socket) { | |||
| 430 | 437 | if (!socket.readable && | |
| 431 | 438 | !socket.writable && | |
| 432 | 439 | !socket.destroyed && | |
| 433 | - !socket._connecting && | ||
| 440 | + !socket.connecting && | ||
| 434 | 441 | !socket._writableState.length) { | |
| 435 | 442 | socket.destroy(); | |
| 436 | 443 | } | |
@@ -465,7 +472,7 @@ Socket.prototype._destroy = function(exception, cb) { | |||
| 465 | 472 | return; | |
| 466 | 473 | } | |
| 467 | 474 | ||
| 468 | - this._connecting = false; | ||
| 475 | + this.connecting = false; | ||
| 469 | 476 | ||
| 470 | 477 | this.readable = this.writable = false; | |
| 471 | 478 | ||
@@ -648,7 +655,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) { | |||
| 648 | 655 | // If we are still connecting, then buffer this for later. | |
| 649 | 656 | // The Writable logic will buffer up any more writes while | |
| 650 | 657 | // waiting for this one to be done. | |
| 651 | - if (this._connecting) { | ||
| 658 | + if (this.connecting) { | ||
| 652 | 659 | this._pendingData = data; | |
| 653 | 660 | this._pendingEncoding = encoding; | |
| 654 | 661 | this.once('connect', function() { | |
@@ -803,7 +810,7 @@ function connect(self, address, port, addressType, localAddress, localPort) { | |||
| 803 | 810 | // TODO return promise from Socket.prototype.connect which | |
| 804 | 811 | // wraps _connectReq. | |
| 805 | 812 | ||
| 806 | - assert.ok(self._connecting); | ||
| 813 | + assert.ok(self.connecting); | ||
| 807 | 814 | ||
| 808 | 815 | var err; | |
| 809 | 816 | ||
@@ -913,7 +920,7 @@ Socket.prototype.connect = function(options, cb) { | |||
| 913 | 920 | ||
| 914 | 921 | this._unrefTimer(); | |
| 915 | 922 | ||
| 916 | - this._connecting = true; | ||
| 923 | + this.connecting = true; | ||
| 917 | 924 | this.writable = true; | |
| 918 | 925 | ||
| 919 | 926 | if (pipe) { | |
@@ -952,7 +959,7 @@ function lookupAndConnect(self, options) { | |||
| 952 | 959 | var addressType = exports.isIP(host); | |
| 953 | 960 | if (addressType) { | |
| 954 | 961 | process.nextTick(function() { | |
| 955 | - if (self._connecting) | ||
| 962 | + if (self.connecting) | ||
| 956 | 963 | connect(self, host, port, addressType, localAddress, localPort); | |
| 957 | 964 | }); | |
| 958 | 965 | return; | |
@@ -980,7 +987,7 @@ function lookupAndConnect(self, options) { | |||
| 980 | 987 | // It's possible we were destroyed while looking this up. | |
| 981 | 988 | // XXX it would be great if we could cancel the promise returned by | |
| 982 | 989 | // the look up. | |
| 983 | - if (!self._connecting) return; | ||
| 990 | + if (!self.connecting) return; | ||
| 984 | 991 | ||
| 985 | 992 | if (err) { | |
| 986 | 993 | // net.createConnection() creates a net.Socket object and | |
@@ -1048,8 +1055,8 @@ function afterConnect(status, handle, req, readable, writable) { | |||
| 1048 | 1055 | ||
| 1049 | 1056 | debug('afterConnect'); | |
| 1050 | 1057 | ||
| 1051 | - assert.ok(self._connecting); | ||
| 1052 | - self._connecting = false; | ||
| 1058 | + assert.ok(self.connecting); | ||
| 1059 | + self.connecting = false; | ||
| 1053 | 1060 | self._sockname = null; | |
| 1054 | 1061 | ||
| 1055 | 1062 | if (status == 0) { | |
@@ -1065,7 +1072,7 @@ function afterConnect(status, handle, req, readable, writable) { | |||
| 1065 | 1072 | self.read(0); | |
| 1066 | 1073 | ||
| 1067 | 1074 | } else { | |
| 1068 | - self._connecting = false; | ||
| 1075 | + self.connecting = false; | ||
| 1069 | 1076 | var details; | |
| 1070 | 1077 | if (req.localAddress && req.localPort) { | |
| 1071 | 1078 | details = req.localAddress + ':' + req.localPort; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,7 @@ tcp.listen(common.PORT, function() { | |||
| 40 | 40 | connectHappened = true; | |
| 41 | 41 | }); | |
| 42 | 42 | ||
| 43 | - console.log('_connecting = ' + socket._connecting); | ||
| 43 | + console.log('connecting = ' + socket.connecting); | ||
| 44 | 44 | ||
| 45 | 45 | assert.equal('opening', socket.readyState); | |
| 46 | 46 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const net = require('net'); | ||
| 5 | + | ||
| 6 | + const server = net.createServer((conn) => { | ||
| 7 | + conn.end(); | ||
| 8 | + server.close(); | ||
| 9 | + }).listen(common.PORT, () => { | ||
| 10 | + const client = net.connect(common.PORT, () => { | ||
| 11 | + assert.strictEqual(client.connecting, false); | ||
| 12 | + | ||
| 13 | + // Legacy getter | ||
| 14 | + assert.strictEqual(client._connecting, false); | ||
| 15 | + client.end(); | ||
| 16 | + }); | ||
| 17 | + assert.strictEqual(client.connecting, true); | ||
| 18 | + | ||
| 19 | + // Legacy getter | ||
| 20 | + assert.strictEqual(client._connecting, true); | ||
| 21 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments