Skip to content

Mark Server and SecureServer as final and mark internal connection handler as internal #71

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

Merged
merged 2 commits into from
Feb 8, 2017
Merged
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ If you want to typehint in your higher-level protocol implementation, you SHOULD
use the generic [`ServerInterface`](#serverinterface) instead.

> Advanced usage: Despite allowing any `ServerInterface` as first parameter,
you SHOULD pass an unmodified `Server` instance as first parameter, unless you
you SHOULD pass a `Server` instance as first parameter, unless you
know what you're doing.
Internally, the `SecureServer` has to set the required TLS context options on
the underlying stream resources.
These resources are not exposed through any of the interfaces defined in this
package, but only through the `React\Stream\Stream` class.
The unmodified `Server` class is guaranteed to emit connections that implement
The `Server` class is guaranteed to emit connections that implement
the `ConnectionInterface` and also extend the `Stream` class in order to
expose these underlying resources.
If you use a custom `ServerInterface` and its `connection` event does not
Expand Down
6 changes: 3 additions & 3 deletions src/SecureServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* @see ServerInterface
* @see ConnectionInterface
*/
class SecureServer extends EventEmitter implements ServerInterface
final class SecureServer extends EventEmitter implements ServerInterface
{
private $tcp;
private $encryption;
Expand Down Expand Up @@ -96,13 +96,13 @@ class SecureServer extends EventEmitter implements ServerInterface
* Passing unknown context options has no effect.
*
* Advanced usage: Despite allowing any `ServerInterface` as first parameter,
* you SHOULD pass an unmodified `Server` instance as first parameter, unless you
* you SHOULD pass a `Server` instance as first parameter, unless you
* know what you're doing.
* Internally, the `SecureServer` has to set the required TLS context options on
* the underlying stream resources.
* These resources are not exposed through any of the interfaces defined in this
* package, but only through the `React\Stream\Stream` class.
* The unmodified `Server` class is guaranteed to emit connections that implement
* The `Server` class is guaranteed to emit connections that implement
* the `ConnectionInterface` and also extend the `Stream` class in order to
* expose these underlying resources.
* If you use a custom `ServerInterface` and its `connection` event does not
Expand Down
20 changes: 7 additions & 13 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @see ServerInterface
* @see ConnectionInterface
*/
class Server extends EventEmitter implements ServerInterface
final class Server extends EventEmitter implements ServerInterface
{
private $master;
private $loop;
Expand Down Expand Up @@ -100,7 +100,7 @@ class Server extends EventEmitter implements ServerInterface
* and/or PHP version.
* Passing unknown context options has no effect.
*
* @param string $uri
* @param string|int $uri
* @param LoopInterface $loop
* @param array $context
* @throws InvalidArgumentException if the listening address is invalid
Expand Down Expand Up @@ -165,15 +165,6 @@ public function __construct($uri, LoopInterface $loop, array $context = array())
});
}

public function handleConnection($socket)
{
stream_set_blocking($socket, 0);

$client = $this->createConnection($socket);

$this->emit('connection', array($client));
}

public function getAddress()
{
if (!is_resource($this->master)) {
Expand Down Expand Up @@ -203,8 +194,11 @@ public function close()
$this->removeAllListeners();
}

public function createConnection($socket)
/** @internal */
public function handleConnection($socket)
{
return new Connection($socket, $this->loop);
$this->emit('connection', array(
new Connection($socket, $this->loop)
));
}
}
9 changes: 5 additions & 4 deletions tests/SecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace React\Tests\Socket;

use React\Socket\SecureServer;
use React\Socket\Server;

class SecureServerTest extends TestCase
{
Expand Down Expand Up @@ -39,10 +40,10 @@ public function testCloseWillBePassedThroughToTcpServer()

public function testConnectionWillBeEndedWithErrorIfItIsNotAStream()
{
$tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->setMethods(null)->getMock();

$loop = $this->getMock('React\EventLoop\LoopInterface');

$tcp = new Server(0, $loop);

$connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
$connection->expects($this->once())->method('end');

Expand All @@ -55,10 +56,10 @@ public function testConnectionWillBeEndedWithErrorIfItIsNotAStream()

public function testSocketErrorWillBeForwarded()
{
$tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->setMethods(null)->getMock();

$loop = $this->getMock('React\EventLoop\LoopInterface');

$tcp = new Server(0, $loop);

$server = new SecureServer($tcp, $loop, array());

$server->on('error', $this->expectCallableOnce());
Expand Down
4 changes: 0 additions & 4 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public function setUp()
}

/**
* @covers React\EventLoop\StreamSelectLoop::tick
* @covers React\Socket\Server::handleConnection
* @covers React\Socket\Server::createConnection
*/
public function testConnection()
{
Expand All @@ -43,9 +41,7 @@ public function testConnection()
}

/**
* @covers React\EventLoop\StreamSelectLoop::tick
* @covers React\Socket\Server::handleConnection
* @covers React\Socket\Server::createConnection
*/
public function testConnectionWithManyClients()
{
Expand Down