Skip to content

Commit

Permalink
Merge branch 'refs/heads/0.2-beta' into wamp-topics
Browse files Browse the repository at this point in the history
Conflicts:
	composer.lock
  • Loading branch information
cboden committed Jul 19, 2012
2 parents b8a677a + 88cba43 commit 9d0e673
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# This file is intended to ease the author's development and testing process
# Users do not need to use `make`; Ratchet does not need to be compiled

test:
phpunit

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ use Ratchet\ConnectionInterface;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;

require __DIR__ . '/vendor/autoload.php';

/**
* chat.php
* Send any incoming messages to all connected clients (except sender)
Expand Down
14 changes: 2 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions src/Ratchet/Server/IoConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@
* {@inheritdoc}
*/
class IoConnection implements ConnectionInterface {
/**
* @var Ratchet\Server\IOServer
*/
protected $server;

/**
* @var React\Socket\ConnectionInterface
*/
protected $conn;

public function __construct(ReactConn $conn, IoServer $server) {
public function __construct(ReactConn $conn) {
$this->conn = $conn;
$this->server = $server;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Ratchet/Server/IoServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class IoServer {
/**
* @param Ratchet\MessageComponentInterface The Ratchet application stack to host
* @param React\Socket\ServerInterface The React socket server to run the Ratchet application off of
* @param React\EventLoop\LoopInterface The React looper to run the Ratchet application off of
* @param React\EventLoop\LoopInterface|null The React looper to run the Ratchet application off of
*/
public function __construct(MessageComponentInterface $app, ServerInterface $socket, LoopInterface $loop) {
public function __construct(MessageComponentInterface $app, ServerInterface $socket, LoopInterface $loop = null) {
gc_enable();
set_time_limit(0);
ob_implicit_flush();
Expand Down Expand Up @@ -64,16 +64,21 @@ public static function factory(MessageComponentInterface $component, $port = 80,

/**
* Run the application by entering the event loop
* @throws RuntimeException If a loop was not previously specified
*/
public function run() {
if (null === $this->loop) {
throw new \RuntimeException("A React Loop was not provided during instantiation");
}

$this->loop->run();
}

/**
* Triggered when a new connection is received from React
*/
public function handleConnect($conn) {
$conn->decor = new IoConnection($conn, $this);
$conn->decor = new IoConnection($conn);

$conn->decor->resourceId = (int)$conn->stream;
$conn->decor->remoteAddress = $conn->getRemoteAddress();
Expand Down
10 changes: 9 additions & 1 deletion tests/Ratchet/Tests/Server/IoServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IoServerTest extends \PHPUnit_Framework_TestCase {
public function setUp() {
$this->app = new Component;

$loop = new StreamSelectLoop(0);
$loop = new StreamSelectLoop;
$this->reactor = new Server($loop);
$this->reactor->listen(0);

Expand Down Expand Up @@ -86,4 +86,12 @@ public function testOnClose() {
public function testFactory() {
$this->assertInstanceOf('\\Ratchet\\Server\\IoServer', IoServer::factory($this->app, 0));
}

public function testNoLoopProvidedError() {
$loop = new StreamSelectLoop;
$io = new IoServer(new Component, new Server($loop));

$this->setExpectedException('RuntimeException');
$io->run();
}
}

0 comments on commit 9d0e673

Please sign in to comment.