@@ -35,6 +35,7 @@ final class FdServer extends EventEmitter implements ServerInterface
3535{
3636 private $ master ;
3737 private $ loop ;
38+ private $ unix = false ;
3839 private $ listening = false ;
3940
4041 /**
@@ -115,6 +116,10 @@ public function __construct($fd, LoopInterface $loop = null)
115116 throw new \RuntimeException ('Failed to listen on FD ' . $ fd . ': ' . $ errstr , $ errno );
116117 }
117118
119+ // Assume this is a Unix domain socket (UDS) when its listening address doesn't parse as a valid URL with a port.
120+ // Looks like this work-around is the closest we can get because PHP doesn't expose SO_DOMAIN even with ext-sockets.
121+ $ this ->unix = \parse_url ($ this ->getAddress (), \PHP_URL_PORT ) === false ;
122+
118123 \stream_set_blocking ($ this ->master , false );
119124
120125 $ this ->resume ();
@@ -128,6 +133,10 @@ public function getAddress()
128133
129134 $ address = \stream_socket_get_name ($ this ->master , false );
130135
136+ if ($ this ->unix === true ) {
137+ return 'unix:// ' . $ address ;
138+ }
139+
131140 // check if this is an IPv6 address which includes multiple colons but no square brackets
132141 $ pos = \strrpos ($ address , ': ' );
133142 if ($ pos !== false && \strpos ($ address , ': ' ) < $ pos && \substr ($ address , 0 , 1 ) !== '[ ' ) {
@@ -180,8 +189,9 @@ public function close()
180189 /** @internal */
181190 public function handleConnection ($ socket )
182191 {
183- $ this ->emit ('connection ' , array (
184- new Connection ($ socket , $ this ->loop )
185- ));
192+ $ connection = new Connection ($ socket , $ this ->loop );
193+ $ connection ->unix = $ this ->unix ;
194+
195+ $ this ->emit ('connection ' , array ($ connection ));
186196 }
187197}
0 commit comments