Browse Source

net: remove unconditional getpeername() call

Speeds up http_simple benchmark by about 1.0%
v0.7.4-release
Ben Noordhuis 13 years ago
committed by Ryan Dahl
parent
commit
1bb820a339
  1. 39
      lib/net_uv.js

39
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++;

Loading…
Cancel
Save