net: introduce Socket#connecting property

There is no official way to figure out if the socket that you have on
hand is still connecting to the remote host. Introduce
`Socket#connecting`, which is essentially an unprefixed `_connecting`
property that we already had.

PR-URL: https://github.com/nodejs/node/pull/6404
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
Fedor Indutny authored and Jeremiah Senkpiel committed 2016-05-03 20:20:30 -04:00
1 parent fb6753c75c
commit cbbe95e1e1
6 files changed
+55 -21

No files matched your search

+1 -1
View File
@@ -40,7 +40,7 @@ tcp.listen(common.PORT, function() {
connectHappened = true;
});
console.log('_connecting = ' + socket._connecting);
console.log('connecting = ' + socket.connecting);
assert.equal('opening', socket.readyState);
@@ -0,0 +1,21 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer((conn) => {
conn.end();
server.close();
}).listen(common.PORT, () => {
const client = net.connect(common.PORT, () => {
assert.strictEqual(client.connecting, false);
// Legacy getter
assert.strictEqual(client._connecting, false);
client.end();
});
assert.strictEqual(client.connecting, true);
// Legacy getter
assert.strictEqual(client._connecting, true);
});