diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2011-08-11 17:41:30 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2011-08-11 17:51:03 +0200 |
commit | 79f064f565abdbdb09b8f394250e02cf2e2ff729 (patch) | |
tree | ad189d220300342eeb62611c2906307ea175fa7e /lib | |
parent | f52a8db280512befb69eecfef8c65bdea48ffcd0 (diff) | |
download | node-new-79f064f565abdbdb09b8f394250e02cf2e2ff729.tar.gz |
net: properly export remoteAddress to user land
Fixes failing test:
test/simple/test-net-remote-address-port.js
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net_legacy.js | 6 | ||||
-rw-r--r-- | lib/net_uv.js | 13 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/net_legacy.js b/lib/net_legacy.js index 4221aa1146..2abe2cde7a 100644 --- a/lib/net_legacy.js +++ b/lib/net_legacy.js @@ -730,6 +730,12 @@ Socket.prototype.connect = function() { if (err) { self.emit('error', err); } else { + addressType = addressType || 4; + + // node_net.cc handles null host names graciously but user land + // expects remoteAddress to have a meaningful value + ip = ip || (addressType === 4 ? '127.0.0.1' : '0:0:0:0:0:0:0:1'); + timers.active(self); self.type = addressType == 4 ? 'tcp4' : 'tcp6'; self.fd = socket(self.type); diff --git a/lib/net_uv.js b/lib/net_uv.js index c89c263bfa..e990cb9aa9 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -69,6 +69,11 @@ function initSocketHandle(self) { if (self._handle) { self._handle.socket = self; self._handle.onread = onread; + + var sockname = self._handle.getsockname(); + self.remoteAddress = sockname.address; + self.remotePort = sockname.port; + // also export sockname.family? } } @@ -464,7 +469,13 @@ Socket.prototype.connect = function(port /* [host], [cb] */) { } else { timers.active(self); - connect(self, ip || '127.0.0.1', port, ip ? addressType : 4); + addressType = addressType || 4; + + // node_net.cc handles null host names graciously but user land + // expects remoteAddress to have a meaningful value + ip = ip || (addressType === 4 ? '127.0.0.1' : '0:0:0:0:0:0:0:1'); + + connect(self, ip, port, addressType); } }); |