Skip to content

Commit 8709947

Browse files
authored
Merge pull request #71 from clue-labs/internal
Mark Server and SecureServer as final and mark internal connection handler as internal
2 parents 234c84a + 30c664e commit 8709947

File tree

5 files changed

+17
-26
lines changed

5 files changed

+17
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ If you want to typehint in your higher-level protocol implementation, you SHOULD
296296
use the generic [`ServerInterface`](#serverinterface) instead.
297297

298298
> Advanced usage: Despite allowing any `ServerInterface` as first parameter,
299-
you SHOULD pass an unmodified `Server` instance as first parameter, unless you
299+
you SHOULD pass a `Server` instance as first parameter, unless you
300300
know what you're doing.
301301
Internally, the `SecureServer` has to set the required TLS context options on
302302
the underlying stream resources.
303303
These resources are not exposed through any of the interfaces defined in this
304304
package, but only through the `React\Stream\Stream` class.
305-
The unmodified `Server` class is guaranteed to emit connections that implement
305+
The `Server` class is guaranteed to emit connections that implement
306306
the `ConnectionInterface` and also extend the `Stream` class in order to
307307
expose these underlying resources.
308308
If you use a custom `ServerInterface` and its `connection` event does not

src/SecureServer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* @see ServerInterface
5353
* @see ConnectionInterface
5454
*/
55-
class SecureServer extends EventEmitter implements ServerInterface
55+
final class SecureServer extends EventEmitter implements ServerInterface
5656
{
5757
private $tcp;
5858
private $encryption;
@@ -96,13 +96,13 @@ class SecureServer extends EventEmitter implements ServerInterface
9696
* Passing unknown context options has no effect.
9797
*
9898
* Advanced usage: Despite allowing any `ServerInterface` as first parameter,
99-
* you SHOULD pass an unmodified `Server` instance as first parameter, unless you
99+
* you SHOULD pass a `Server` instance as first parameter, unless you
100100
* know what you're doing.
101101
* Internally, the `SecureServer` has to set the required TLS context options on
102102
* the underlying stream resources.
103103
* These resources are not exposed through any of the interfaces defined in this
104104
* package, but only through the `React\Stream\Stream` class.
105-
* The unmodified `Server` class is guaranteed to emit connections that implement
105+
* The `Server` class is guaranteed to emit connections that implement
106106
* the `ConnectionInterface` and also extend the `Stream` class in order to
107107
* expose these underlying resources.
108108
* If you use a custom `ServerInterface` and its `connection` event does not

src/Server.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* @see ServerInterface
3535
* @see ConnectionInterface
3636
*/
37-
class Server extends EventEmitter implements ServerInterface
37+
final class Server extends EventEmitter implements ServerInterface
3838
{
3939
private $master;
4040
private $loop;
@@ -100,7 +100,7 @@ class Server extends EventEmitter implements ServerInterface
100100
* and/or PHP version.
101101
* Passing unknown context options has no effect.
102102
*
103-
* @param string $uri
103+
* @param string|int $uri
104104
* @param LoopInterface $loop
105105
* @param array $context
106106
* @throws InvalidArgumentException if the listening address is invalid
@@ -165,15 +165,6 @@ public function __construct($uri, LoopInterface $loop, array $context = array())
165165
});
166166
}
167167

168-
public function handleConnection($socket)
169-
{
170-
stream_set_blocking($socket, 0);
171-
172-
$client = $this->createConnection($socket);
173-
174-
$this->emit('connection', array($client));
175-
}
176-
177168
public function getAddress()
178169
{
179170
if (!is_resource($this->master)) {
@@ -203,8 +194,11 @@ public function close()
203194
$this->removeAllListeners();
204195
}
205196

206-
public function createConnection($socket)
197+
/** @internal */
198+
public function handleConnection($socket)
207199
{
208-
return new Connection($socket, $this->loop);
200+
$this->emit('connection', array(
201+
new Connection($socket, $this->loop)
202+
));
209203
}
210204
}

tests/SecureServerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace React\Tests\Socket;
44

55
use React\Socket\SecureServer;
6+
use React\Socket\Server;
67

78
class SecureServerTest extends TestCase
89
{
@@ -39,10 +40,10 @@ public function testCloseWillBePassedThroughToTcpServer()
3940

4041
public function testConnectionWillBeEndedWithErrorIfItIsNotAStream()
4142
{
42-
$tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->setMethods(null)->getMock();
43-
4443
$loop = $this->getMock('React\EventLoop\LoopInterface');
4544

45+
$tcp = new Server(0, $loop);
46+
4647
$connection = $this->getMockBuilder('React\Socket\ConnectionInterface')->getMock();
4748
$connection->expects($this->once())->method('end');
4849

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

5657
public function testSocketErrorWillBeForwarded()
5758
{
58-
$tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->setMethods(null)->getMock();
59-
6059
$loop = $this->getMock('React\EventLoop\LoopInterface');
6160

61+
$tcp = new Server(0, $loop);
62+
6263
$server = new SecureServer($tcp, $loop, array());
6364

6465
$server->on('error', $this->expectCallableOnce());

tests/ServerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ public function setUp()
3030
}
3131

3232
/**
33-
* @covers React\EventLoop\StreamSelectLoop::tick
3433
* @covers React\Socket\Server::handleConnection
35-
* @covers React\Socket\Server::createConnection
3634
*/
3735
public function testConnection()
3836
{
@@ -43,9 +41,7 @@ public function testConnection()
4341
}
4442

4543
/**
46-
* @covers React\EventLoop\StreamSelectLoop::tick
4744
* @covers React\Socket\Server::handleConnection
48-
* @covers React\Socket\Server::createConnection
4945
*/
5046
public function testConnectionWithManyClients()
5147
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy