create a new connection when path is the same
This commit is contained in:
@@ -64,13 +64,17 @@ public class IO {
|
||||
} catch (URISyntaxException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String id = Url.extractId(parsed);
|
||||
String path = parsed.getPath();
|
||||
boolean sameNamespace = managers.containsKey(id)
|
||||
&& managers.get(id).nsps.containsKey(path);
|
||||
boolean newConnection = opts.forceNew || !opts.multiplex || sameNamespace;
|
||||
Manager io;
|
||||
|
||||
if (opts.forceNew || !opts.multiplex) {
|
||||
if (newConnection) {
|
||||
logger.fine(String.format("ignoring socket cache for %s", source));
|
||||
io = new Manager(source, opts);
|
||||
} else {
|
||||
String id = Url.extractId(parsed);
|
||||
if (!managers.containsKey(id)) {
|
||||
logger.fine(String.format("new io instance for %s", source));
|
||||
managers.putIfAbsent(id, new Manager(source, opts));
|
||||
|
||||
@@ -96,7 +96,7 @@ public class Manager extends Emitter {
|
||||
/**
|
||||
* This HashMap can be accessed from outside of EventThread.
|
||||
*/
|
||||
private ConcurrentHashMap<String, Socket> nsps;
|
||||
/*package*/ ConcurrentHashMap<String, Socket> nsps;
|
||||
|
||||
|
||||
public Manager() {
|
||||
|
||||
@@ -81,8 +81,16 @@ public abstract class Connection {
|
||||
return client(createOptions());
|
||||
}
|
||||
|
||||
Socket client(String path) throws URISyntaxException {
|
||||
return IO.socket(path, createOptions());
|
||||
}
|
||||
|
||||
Socket client(IO.Options opts) throws URISyntaxException {
|
||||
return IO.socket(uri() + nsp(), opts);
|
||||
return client(nsp(), opts);
|
||||
}
|
||||
|
||||
Socket client(String path, IO.Options opts) throws URISyntaxException {
|
||||
return IO.socket(uri() + path, opts);
|
||||
}
|
||||
|
||||
String uri() {
|
||||
|
||||
@@ -19,6 +19,8 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
@@ -47,6 +49,26 @@ public class ConnectionTest extends Connection {
|
||||
socket.close();
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void startTwoConnectionsWithSamePath() throws URISyntaxException, InterruptedException {
|
||||
Socket s1 = client("/");
|
||||
Socket s2 = client("/");
|
||||
|
||||
assertThat(s1.io(), not(equalTo(s2.io())));
|
||||
s1.close();
|
||||
s2.close();
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void startTwoConnectionsWithSamePathAndDifferentQuerystrings() throws URISyntaxException, InterruptedException {
|
||||
Socket s1 = client("/?woot");
|
||||
Socket s2 = client("/");
|
||||
|
||||
assertThat(s1.io(), not(equalTo(s2.io())));
|
||||
s1.close();
|
||||
s2.close();
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
public void workWithAcks() throws URISyntaxException, InterruptedException {
|
||||
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
|
||||
|
||||
Reference in New Issue
Block a user