Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[fix] short circuit in the add function if !this.multiplex to prevent…
… potential inefficiency
  • Loading branch information
jcrugzz committed Dec 1, 2013
1 parent 7d5bd63 commit 58d4535
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/godot/net/server.js
Expand Up @@ -75,15 +75,20 @@ Server.prototype.add = function (reactor) {
this.reactors[reactor.id] = reactor;
//
// Add reactor to the running set
// Remark: there will only be one host
// Remark: there will only be one host in case of multiplex = false;
// Lets special case this so we aren't adding reactors unnecessarily
// See createReactors function for why
//
var keys = Object.keys(this.hosts);
if (keys.length) {
if (!this.multiplex) {
return this.hosts['default'].push(this.createReactor(reactor.id));
}

for(var i=0; i<keys.length; i++) {
this.hosts[keys[i]].push(this.createReactor(reactor.id));
}
}

};

//
Expand Down Expand Up @@ -232,6 +237,12 @@ Server.prototype.createReactors = function (id) {
var self = this;

if (!this.hosts[id]) {
//
// Remark: If we are not creating a new set of streams
// for each new connection (multiplex = false), then for
// each new connection, have it point to the default
// Reactors that were instantiated.
//
if (!this.multiplex && this.hosts['default']) {
this.hosts[id] = this.hosts['default'];
return;
Expand Down

0 comments on commit 58d4535

Please sign in to comment.