Browse Source

net: properly export remoteAddress to user land

Fixes failing test:
  test/simple/test-net-remote-address-port.js
v0.7.4-release
Ben Noordhuis 14 years ago
parent
commit
79f064f565
  1. 6
      lib/net_legacy.js
  2. 13
      lib/net_uv.js
  3. 4
      test/simple/test-net-remote-address-port.js

6
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);

13
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);
}
});

4
test/simple/test-net-remote-address-port.js

@ -3,13 +3,13 @@ var assert = require('assert');
var net = require('net');
var conns = 0;
var conns = 0, conns_closed = 0;
var server = net.createServer(function(socket) {
conns++;
assert.equal('127.0.0.1', socket.remoteAddress);
socket.on('end', function() {
server.close();
if (++conns_closed == 2) server.close();
});
});

Loading…
Cancel
Save