-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: introduce Socket#connecting
property
#6404
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,7 @@ const BYTES_READ = Symbol('bytesRead'); | |
function Socket(options) { | ||
if (!(this instanceof Socket)) return new Socket(options); | ||
|
||
this._connecting = false; | ||
this.connecting = false; | ||
this._hadError = false; | ||
this._handle = null; | ||
this._parent = null; | ||
|
@@ -202,7 +202,7 @@ Socket.prototype._unrefTimer = function unrefTimer() { | |
// so that only the writable side will be cleaned up. | ||
function onSocketFinish() { | ||
// If still connecting - defer handling 'finish' until 'connect' will happen | ||
if (this._connecting) { | ||
if (this.connecting) { | ||
debug('osF: not yet connected'); | ||
return this.once('connect', onSocketFinish); | ||
} | ||
|
@@ -367,9 +367,16 @@ Socket.prototype.address = function() { | |
}; | ||
|
||
|
||
Object.defineProperty(Socket.prototype, '_connecting', { | ||
get: function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should there be a deprecation message here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ChALkeR Can you check how many people are using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @evanlucas it should be, will do it in a follow-up PR, because it won't be backported. |
||
return this.connecting; | ||
} | ||
}); | ||
|
||
|
||
Object.defineProperty(Socket.prototype, 'readyState', { | ||
get: function() { | ||
if (this._connecting) { | ||
if (this.connecting) { | ||
return 'opening'; | ||
} else if (this.readable && this.writable) { | ||
return 'open'; | ||
|
@@ -397,7 +404,7 @@ Object.defineProperty(Socket.prototype, 'bufferSize', { | |
Socket.prototype._read = function(n) { | ||
debug('_read'); | ||
|
||
if (this._connecting || !this._handle) { | ||
if (this.connecting || !this._handle) { | ||
debug('_read wait for connection'); | ||
this.once('connect', () => this._read(n)); | ||
} else if (!this._handle.reading) { | ||
|
@@ -430,7 +437,7 @@ function maybeDestroy(socket) { | |
if (!socket.readable && | ||
!socket.writable && | ||
!socket.destroyed && | ||
!socket._connecting && | ||
!socket.connecting && | ||
!socket._writableState.length) { | ||
socket.destroy(); | ||
} | ||
|
@@ -465,7 +472,7 @@ Socket.prototype._destroy = function(exception, cb) { | |
return; | ||
} | ||
|
||
this._connecting = false; | ||
this.connecting = false; | ||
|
||
this.readable = this.writable = false; | ||
|
||
|
@@ -648,7 +655,7 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) { | |
// If we are still connecting, then buffer this for later. | ||
// The Writable logic will buffer up any more writes while | ||
// waiting for this one to be done. | ||
if (this._connecting) { | ||
if (this.connecting) { | ||
this._pendingData = data; | ||
this._pendingEncoding = encoding; | ||
this.once('connect', function() { | ||
|
@@ -803,7 +810,7 @@ function connect(self, address, port, addressType, localAddress, localPort) { | |
// TODO return promise from Socket.prototype.connect which | ||
// wraps _connectReq. | ||
|
||
assert.ok(self._connecting); | ||
assert.ok(self.connecting); | ||
|
||
var err; | ||
|
||
|
@@ -913,7 +920,7 @@ Socket.prototype.connect = function(options, cb) { | |
|
||
this._unrefTimer(); | ||
|
||
this._connecting = true; | ||
this.connecting = true; | ||
this.writable = true; | ||
|
||
if (pipe) { | ||
|
@@ -952,7 +959,7 @@ function lookupAndConnect(self, options) { | |
var addressType = exports.isIP(host); | ||
if (addressType) { | ||
process.nextTick(function() { | ||
if (self._connecting) | ||
if (self.connecting) | ||
connect(self, host, port, addressType, localAddress, localPort); | ||
}); | ||
return; | ||
|
@@ -980,7 +987,7 @@ function lookupAndConnect(self, options) { | |
// It's possible we were destroyed while looking this up. | ||
// XXX it would be great if we could cancel the promise returned by | ||
// the look up. | ||
if (!self._connecting) return; | ||
if (!self.connecting) return; | ||
|
||
if (err) { | ||
// net.createConnection() creates a net.Socket object and | ||
|
@@ -1048,8 +1055,8 @@ function afterConnect(status, handle, req, readable, writable) { | |
|
||
debug('afterConnect'); | ||
|
||
assert.ok(self._connecting); | ||
self._connecting = false; | ||
assert.ok(self.connecting); | ||
self.connecting = false; | ||
self._sockname = null; | ||
|
||
if (status == 0) { | ||
|
@@ -1065,7 +1072,7 @@ function afterConnect(status, handle, req, readable, writable) { | |
self.read(0); | ||
|
||
} else { | ||
self._connecting = false; | ||
self.connecting = false; | ||
var details; | ||
if (req.localAddress && req.localPort) { | ||
details = req.localAddress + ':' + req.localPort; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ tcp.listen(common.PORT, function() { | |
connectHappened = true; | ||
}); | ||
|
||
console.log('_connecting = ' + socket._connecting); | ||
console.log('_connecting = ' + socket.connecting); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the text also be changed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't really matter, IMO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing the text might save someone a cycle or two if the test fails and they start poking around trying to figure out why... probably slightly more time than it took me to write this (almost none, but non-zero). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rmg I disagree, but will change it. Ack. |
||
|
||
assert.equal('opening', socket.readyState); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.equal(client.connecting, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. strictEqual would be better I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack. |
||
|
||
// Legacy getter | ||
assert.equal(client._connecting, false); | ||
client.end(); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did this pass linter? I think semicolon is missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't, sorry! I added test after doing lint, so it didn't show it. |
||
assert.equal(client.connecting, true); | ||
|
||
// Legacy getter | ||
assert.equal(client._connecting, true); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be below
socket.bufferSize
to keep them in alphabetical order.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.