Skip to content

Commit

Permalink
bugfix/1956 don't reuse same-namespace connections socketio#2
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-luo committed Jan 25, 2015
1 parent 2079467 commit 7d237cc
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,36 +45,25 @@ function lookup(uri, opts) {
var source = parsed.source;
var id = parsed.id;
var path = parsed.path;
var host = parsed.host;
var port = parsed.port;
var scheme = parsed.protocol;
var sameNamespace = (cache[id] && cache[id].nsps[path] &&
path == cache[id].nsps[path].nsp);
var newConnection = opts.forceNew || opts['force new connection'] ||
false === opts.multiplex || sameNamespace;

var io;

if (opts.forceNew || opts['force new connection'] || false === opts.multiplex) {
if (newConnection) {
debug('ignoring socket cache for %s', source);
io = Manager(source, opts);
return io.socket(path);
}

if (cache[id]) {
var cachedPath = cache[id].nsps[path].nsp;
var cachedHost = cache[id].opts.host;
var cachedPort = cache[id].opts.port;
var cachedScheme = cache[id].uri.substr(0, cache[id].uri.indexOf(':'));

if (path === cachedPath && host === cachedHost &&
port === cachedPort && scheme === cachedScheme) {
debug('in cache but ignoring socket cache for %s', source)
io = Manager(source, opts);
return io.socket(path);
}
} else {
debug('new io instance for %s', source);
cache[id] = Manager(source, opts);
if (!cache[id]) {
debug('new io instance for %s', source);
cache[id] = Manager(source, opts);
}
io = cache[id];
}

io = cache[id];
return io.socket(path);
return io.socket(parsed.path);
}

/**
Expand Down

0 comments on commit 7d237cc

Please sign in to comment.