File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -54,12 +54,24 @@ protected function resolveAddress($address)
54
54
if (strpos ($ address , ':// ' ) === false ) {
55
55
$ address = 'udp:// ' . $ address ;
56
56
}
57
+
58
+ // parse_url() does not accept null ports (random port assignment) => manually remove
59
+ $ nullport = false ;
60
+ if (substr ($ address , -2 ) === ':0 ' ) {
61
+ $ address = substr ($ address , 0 , -2 );
62
+ $ nullport = true ;
63
+ }
64
+
57
65
$ parts = parse_url ($ address );
58
66
59
67
if (!$ parts || !isset ($ parts ['host ' ])) {
60
68
return When::resolve ($ address );
61
69
}
62
70
71
+ if ($ nullport ) {
72
+ $ parts ['port ' ] = 0 ;
73
+ }
74
+
63
75
// remove square brackets for IPv6 addresses
64
76
$ host = trim ($ parts ['host ' ], '[] ' );
65
77
Original file line number Diff line number Diff line change @@ -53,4 +53,16 @@ public function testCreateServer()
53
53
54
54
$ capturedServer ->close ();
55
55
}
56
+
57
+ public function testCreateServerRandomPort ()
58
+ {
59
+ $ promise = $ this ->factory ->createServer ('127.0.0.1:0 ' );
60
+
61
+ $ capturedServer = $ this ->getValueFromResolvedPromise ($ promise );
62
+ $ this ->assertInstanceOf ('Datagram\Socket ' , $ capturedServer );
63
+
64
+ $ this ->assertNotEquals ('127.0.0.1:0 ' , $ capturedServer ->getLocalAddress ());
65
+
66
+ $ capturedServer ->close ();
67
+ }
56
68
}
You can’t perform that action at this time.
0 commit comments