diff --git a/src/Server.php b/src/Server.php index 76e2cf9b..3914893c 100644 --- a/src/Server.php +++ b/src/Server.php @@ -23,9 +23,14 @@ public function listen($port, $host = '127.0.0.1') $host = '[' . $host . ']'; } - $this->master = @stream_socket_server("tcp://$host:$port", $errno, $errstr); + $this->bind("tcp://$host:$port"); + } + + public function bind($address) + { + $this->master = @stream_socket_server($address, $errno, $errstr); if (false === $this->master) { - $message = "Could not bind to tcp://$host:$port: $errstr"; + $message = "Could not bind to $address: $errstr"; throw new ConnectionException($message, $errno); } stream_set_blocking($this->master, 0); diff --git a/src/ServerInterface.php b/src/ServerInterface.php index 85ab0ed5..c1563323 100644 --- a/src/ServerInterface.php +++ b/src/ServerInterface.php @@ -8,6 +8,7 @@ interface ServerInterface extends EventEmitterInterface { public function listen($port, $host = '127.0.0.1'); + public function bind($address); public function getPort(); public function shutdown(); } diff --git a/tests/ServerTest.php b/tests/ServerTest.php index ba2c4aa1..42d36650 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -43,6 +43,24 @@ public function testConnection() $this->loop->tick(); } + /** + * @covers React\EventLoop\StreamSelectLoop::tick + * @covers React\Socket\Server::handleConnection + * @covers React\Socket\Server::createConnection + */ + public function testUnixConnection() + { + $unixSocket = 'unix://./server.sock'; + + $server = new Server($this->loop); + $server->bind($unixSocket); + + $client = stream_socket_client($unixSocket); + + $server->on('connection', $this->expectCallableOnce()); + $this->loop->tick(); + } + /** * @covers React\EventLoop\StreamSelectLoop::tick * @covers React\Socket\Server::handleConnection