Merge branch 'clue-labs/socket' into 0.4

# Conflicts:
#	composer.json
#	tests/autobahn/bin/fuzzingserver-noutf8.php
#	tests/autobahn/bin/fuzzingserver.php
This commit is contained in:
Chris Boden 2017-02-16 20:31:29 -05:00
commit 131204eaf5
5 changed files with 15 additions and 16 deletions

View File

@ -28,7 +28,7 @@
, "require": { , "require": {
"php": ">=5.4.2" "php": ">=5.4.2"
, "ratchet/rfc6455": "^0.2" , "ratchet/rfc6455": "^0.2"
, "react/socket": "^0.3 || ^0.4" , "react/socket": "^0.5"
, "guzzlehttp/psr7": "^1.0" , "guzzlehttp/psr7": "^1.0"
, "symfony/http-foundation": "^2.2|^3.0" , "symfony/http-foundation": "^2.2|^3.0"
, "symfony/routing": "^2.2|^3.0" , "symfony/routing": "^2.2|^3.0"

View File

@ -76,8 +76,7 @@ class App {
$this->httpHost = $httpHost; $this->httpHost = $httpHost;
$this->port = $port; $this->port = $port;
$socket = new Reactor($loop); $socket = new Reactor($address . ':' . $port, $loop);
$socket->listen($port, $address);
$this->routes = new RouteCollection; $this->routes = new RouteCollection;
$this->_server = new IoServer(new HttpServer(new Router(new UrlMatcher($this->routes, new RequestContext))), $socket, $loop); $this->_server = new IoServer(new HttpServer(new Router(new UrlMatcher($this->routes, new RequestContext))), $socket, $loop);
@ -85,13 +84,14 @@ class App {
$policy = new FlashPolicy; $policy = new FlashPolicy;
$policy->addAllowedAccess($httpHost, 80); $policy->addAllowedAccess($httpHost, 80);
$policy->addAllowedAccess($httpHost, $port); $policy->addAllowedAccess($httpHost, $port);
$flashSock = new Reactor($loop);
$this->flashServer = new IoServer($policy, $flashSock);
if (80 == $port) { if (80 == $port) {
$flashSock->listen(843, '0.0.0.0'); $flashUri = '0.0.0.0:843';
} else { } else {
$flashSock->listen(8843); $flashUri = 8843;
} }
$flashSock = new Reactor($flashUri, $loop);
$this->flashServer = new IoServer($policy, $flashSock);
} }
/** /**

View File

@ -66,8 +66,7 @@ class IoServer {
*/ */
public static function factory(MessageComponentInterface $component, $port = 80, $address = '0.0.0.0') { public static function factory(MessageComponentInterface $component, $port = 80, $address = '0.0.0.0') {
$loop = LoopFactory::create(); $loop = LoopFactory::create();
$socket = new Reactor($loop); $socket = new Reactor($address . ':' . $port, $loop);
$socket->listen($port, $address);
return new static($component, $socket, $loop); return new static($component, $socket, $loop);
} }
@ -94,7 +93,10 @@ class IoServer {
$conn->decor = new IoConnection($conn); $conn->decor = new IoConnection($conn);
$conn->decor->resourceId = (int)$conn->stream; $conn->decor->resourceId = (int)$conn->stream;
$conn->decor->remoteAddress = $conn->getRemoteAddress(); $conn->decor->remoteAddress = trim(
parse_url('tcp://' . $conn->getRemoteAddress(), PHP_URL_HOST),
'[]'
);
$this->app->onOpen($conn->decor); $this->app->onOpen($conn->decor);

View File

@ -22,7 +22,7 @@ class BinaryEcho implements \Ratchet\WebSocket\MessageComponentInterface {
$impl = sprintf('React\EventLoop\%sLoop', $argc > 2 ? $argv[2] : 'StreamSelect'); $impl = sprintf('React\EventLoop\%sLoop', $argc > 2 ? $argv[2] : 'StreamSelect');
$loop = new $impl; $loop = new $impl;
$sock = new React\Socket\Server($loop); $sock = new React\Socket\Server('0.0.0.0:' . $port, $loop);
$wsServer = new Ratchet\WebSocket\WsServer(new BinaryEcho); $wsServer = new Ratchet\WebSocket\WsServer(new BinaryEcho);
// This is enabled to test https://github.com/ratchetphp/Ratchet/issues/430 // This is enabled to test https://github.com/ratchetphp/Ratchet/issues/430
@ -32,7 +32,5 @@ class BinaryEcho implements \Ratchet\WebSocket\MessageComponentInterface {
$app = new Ratchet\Http\HttpServer($wsServer); $app = new Ratchet\Http\HttpServer($wsServer);
$sock->listen($port, '0.0.0.0');
$server = new Ratchet\Server\IoServer($app, $sock, $loop); $server = new Ratchet\Server\IoServer($app, $sock, $loop);
$server->run(); $server->run();

View File

@ -20,10 +20,9 @@ class IoServerTest extends \PHPUnit_Framework_TestCase {
$this->app = $this->getMock('\\Ratchet\\MessageComponentInterface'); $this->app = $this->getMock('\\Ratchet\\MessageComponentInterface');
$loop = new StreamSelectLoop; $loop = new StreamSelectLoop;
$this->reactor = new Server($loop); $this->reactor = new Server(0, $loop);
$this->reactor->listen(0);
$this->port = $this->reactor->getPort(); $this->port = parse_url('tcp://' . $this->reactor->getAddress(), PHP_URL_PORT);
$this->server = new IoServer($this->app, $this->reactor, $loop); $this->server = new IoServer($this->app, $this->reactor, $loop);
} }