net: properly export remoteAddress to user land
Fixes failing test: test/simple/test-net-remote-address-port.js
This commit is contained in:
Родитель
f52a8db280
Коммит
79f064f565
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче