File tree Expand file tree Collapse file tree 4 files changed +38
-4
lines changed
main/java/io/socket/client
test/java/io/socket/client Expand file tree Collapse file tree 4 files changed +38
-4
lines changed Original file line number Diff line number Diff line change @@ -64,13 +64,17 @@ public static Socket socket(URI uri, Options opts) {
6464 } catch (URISyntaxException e ) {
6565 throw new RuntimeException (e );
6666 }
67+ String id = Url .extractId (parsed );
68+ String path = parsed .getPath ();
69+ boolean sameNamespace = managers .containsKey (id )
70+ && managers .get (id ).nsps .containsKey (path );
71+ boolean newConnection = opts .forceNew || !opts .multiplex || sameNamespace ;
6772 Manager io ;
6873
69- if (opts . forceNew || ! opts . multiplex ) {
74+ if (newConnection ) {
7075 logger .fine (String .format ("ignoring socket cache for %s" , source ));
7176 io = new Manager (source , opts );
7277 } else {
73- String id = Url .extractId (parsed );
7478 if (!managers .containsKey (id )) {
7579 logger .fine (String .format ("new io instance for %s" , source ));
7680 managers .putIfAbsent (id , new Manager (source , opts ));
Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ public class Manager extends Emitter {
9696 /**
9797 * This HashMap can be accessed from outside of EventThread.
9898 */
99- private ConcurrentHashMap <String , Socket > nsps ;
99+ /*package*/ ConcurrentHashMap <String , Socket > nsps ;
100100
101101
102102 public Manager () {
Original file line number Diff line number Diff line change @@ -81,8 +81,16 @@ Socket client() throws URISyntaxException {
8181 return client (createOptions ());
8282 }
8383
84+ Socket client (String path ) throws URISyntaxException {
85+ return IO .socket (path , createOptions ());
86+ }
87+
8488 Socket client (IO .Options opts ) throws URISyntaxException {
85- return IO .socket (uri () + nsp (), opts );
89+ return client (nsp (), opts );
90+ }
91+
92+ Socket client (String path , IO .Options opts ) throws URISyntaxException {
93+ return IO .socket (uri () + path , opts );
8694 }
8795
8896 String uri () {
Original file line number Diff line number Diff line change 1919
2020import static org .hamcrest .CoreMatchers .instanceOf ;
2121import static org .hamcrest .CoreMatchers .is ;
22+ import static org .hamcrest .CoreMatchers .equalTo ;
23+ import static org .hamcrest .CoreMatchers .not ;
2224import static org .junit .Assert .assertThat ;
2325
2426@ RunWith (JUnit4 .class )
@@ -47,6 +49,26 @@ public void call(Object... args) {
4749 socket .close ();
4850 }
4951
52+ @ Test (timeout = TIMEOUT )
53+ public void startTwoConnectionsWithSamePath () throws URISyntaxException , InterruptedException {
54+ Socket s1 = client ("/" );
55+ Socket s2 = client ("/" );
56+
57+ assertThat (s1 .io (), not (equalTo (s2 .io ())));
58+ s1 .close ();
59+ s2 .close ();
60+ }
61+
62+ @ Test (timeout = TIMEOUT )
63+ public void startTwoConnectionsWithSamePathAndDifferentQuerystrings () throws URISyntaxException , InterruptedException {
64+ Socket s1 = client ("/?woot" );
65+ Socket s2 = client ("/" );
66+
67+ assertThat (s1 .io (), not (equalTo (s2 .io ())));
68+ s1 .close ();
69+ s2 .close ();
70+ }
71+
5072 @ Test (timeout = TIMEOUT )
5173 public void workWithAcks () throws URISyntaxException , InterruptedException {
5274 final BlockingQueue <Object > values = new LinkedBlockingQueue <Object >();
You can’t perform that action at this time.
0 commit comments