Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a more generic bind() method to allow Unix socket server #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/ServerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
18 changes: 18 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down