diff --git a/lib/net_uv.js b/lib/net_uv.js index 7230c9379f..6fb0934230 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -342,6 +342,27 @@ Socket.prototype.setEncoding = function(encoding) { }; +Socket.prototype._getpeername = function() { + if (!this._handle || !this._handle.getpeername) { + return {}; + } + if (!this._peername) { + this._peername = this._handle.getpeername(); + } + return this._peername; +}; + + +Socket.prototype.__defineGetter__('remoteAddress', function() { + return this._getpeername().address; +}); + + +Socket.prototype.__defineGetter__('remotePort', function() { + return this._getpeername().port; +}); + + Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) { var encoding, fd, cb; @@ -693,7 +714,6 @@ Server.prototype.address = function() { function onconnection(clientHandle) { var handle = this; var self = handle.socket; - var peername; debug('onconnection'); @@ -707,29 +727,12 @@ function onconnection(clientHandle) { return; } - // Todo: implement this for unix sockets - if (clientHandle.getpeername) { - peername = clientHandle.getpeername(); - if (!peername.address || !peername.port) { - var err = errnoException(errno, 'accept'); - clientHandle.close(); - self.emit('error', err); - return; - } - } - var socket = new Socket({ handle: clientHandle, allowHalfOpen: self.allowHalfOpen }); socket.readable = socket.writable = true; - if (peername) { - socket.remoteAddress = peername.address; - socket.remotePort = peername.port; - // TODO: set family as well - } - socket.resume(); self.connections++;