net: remove unconditional getpeername() call
Speeds up http_simple benchmark by about 1.0%
This commit is contained in:
parent
ed65b7b375
commit
1bb820a339
@ -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] */) {
|
Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) {
|
||||||
var encoding, fd, cb;
|
var encoding, fd, cb;
|
||||||
|
|
||||||
@ -693,7 +714,6 @@ Server.prototype.address = function() {
|
|||||||
function onconnection(clientHandle) {
|
function onconnection(clientHandle) {
|
||||||
var handle = this;
|
var handle = this;
|
||||||
var self = handle.socket;
|
var self = handle.socket;
|
||||||
var peername;
|
|
||||||
|
|
||||||
debug('onconnection');
|
debug('onconnection');
|
||||||
|
|
||||||
@ -707,29 +727,12 @@ function onconnection(clientHandle) {
|
|||||||
return;
|
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({
|
var socket = new Socket({
|
||||||
handle: clientHandle,
|
handle: clientHandle,
|
||||||
allowHalfOpen: self.allowHalfOpen
|
allowHalfOpen: self.allowHalfOpen
|
||||||
});
|
});
|
||||||
socket.readable = socket.writable = true;
|
socket.readable = socket.writable = true;
|
||||||
|
|
||||||
if (peername) {
|
|
||||||
socket.remoteAddress = peername.address;
|
|
||||||
socket.remotePort = peername.port;
|
|
||||||
// TODO: set family as well
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.resume();
|
socket.resume();
|
||||||
|
|
||||||
self.connections++;
|
self.connections++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user