Skip to content

Commit e4fb0f2

Browse files
committed
SecureServer supports any underlying ServerInterface (advanced)
1 parent f0bd619 commit e4fb0f2

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,19 @@ Note that the `SecureServer` class is a concrete implementation for TLS sockets.
295295
If you want to typehint in your higher-level protocol implementation, you SHOULD
296296
use the generic [`ServerInterface`](#serverinterface) instead.
297297

298-
> Advanced usage: Internally, the `SecureServer` has to set the required
299-
context options on the underlying stream resources.
300-
It should therefor be used with an unmodified `Server` instance as first
301-
parameter so that it can allocate an empty context resource which this
302-
class uses to set required TLS context options.
303-
Failing to do so may result in some hard to trace race conditions,
304-
because all stream resources will use a single, shared default context
305-
resource otherwise.
298+
> Advanced usage: Despite allowing any `ServerInterface` as first parameter,
299+
you SHOULD pass an unmodified `Server` instance as first parameter, unless you
300+
know what you're doing.
301+
Internally, the `SecureServer` has to set the required TLS context options on
302+
the underlying stream resources.
303+
These resources are not exposed through any of the interfaces defined in this
304+
package, but only through the `React\Stream\Stream` class.
305+
The unmodified `Server` class is guaranteed to emit connections that implement
306+
the `ConnectionInterface` and also extend the `Stream` class in order to
307+
expose these underlying resources.
308+
If you use a custom `ServerInterface` and its `connection` event does not
309+
meet this requirement, the `SecureServer` will emit an `error` event and
310+
then close the underlying connection.
306311

307312
### ConnectionInterface
308313

src/SecureServer.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,27 @@ class SecureServer extends EventEmitter implements ServerInterface
9595
* and/or PHP version.
9696
* Passing unknown context options has no effect.
9797
*
98-
* Advanced usage: Internally, the `SecureServer` has to set the required
99-
* context options on the underlying stream resources.
100-
* It should therefor be used with an unmodified `Server` instance as first
101-
* parameter so that it can allocate an empty context resource which this
102-
* class uses to set required TLS context options.
103-
* Failing to do so may result in some hard to trace race conditions,
104-
* because all stream resources will use a single, shared default context
105-
* resource otherwise.
98+
* Advanced usage: Despite allowing any `ServerInterface` as first parameter,
99+
* you SHOULD pass an unmodified `Server` instance as first parameter, unless you
100+
* know what you're doing.
101+
* Internally, the `SecureServer` has to set the required TLS context options on
102+
* the underlying stream resources.
103+
* These resources are not exposed through any of the interfaces defined in this
104+
* package, but only through the `React\Stream\Stream` class.
105+
* The unmodified `Server` class is guaranteed to emit connections that implement
106+
* the `ConnectionInterface` and also extend the `Stream` class in order to
107+
* expose these underlying resources.
108+
* If you use a custom `ServerInterface` and its `connection` event does not
109+
* meet this requirement, the `SecureServer` will emit an `error` event and
110+
* then close the underlying connection.
106111
*
107-
* @param Server $tcp
112+
* @param ServerInterface|Server $tcp
108113
* @param LoopInterface $loop
109114
* @param array $context
110115
* @see Server
111116
* @link http://php.net/manual/en/context.ssl.php for TLS context options
112117
*/
113-
public function __construct(Server $tcp, LoopInterface $loop, array $context)
118+
public function __construct(ServerInterface $tcp, LoopInterface $loop, array $context)
114119
{
115120
// default to empty passphrase to surpress blocking passphrase prompt
116121
$context += array(

tests/SecureServerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function setUp()
1515

1616
public function testGetAddressWillBePassedThroughToTcpServer()
1717
{
18-
$tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->getMock();
18+
$tcp = $this->getMockBuilder('React\Socket\ServerInterface')->getMock();
1919
$tcp->expects($this->once())->method('getAddress')->willReturn('127.0.0.1:1234');
2020

2121
$loop = $this->getMock('React\EventLoop\LoopInterface');
@@ -27,7 +27,7 @@ public function testGetAddressWillBePassedThroughToTcpServer()
2727

2828
public function testCloseWillBePassedThroughToTcpServer()
2929
{
30-
$tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->getMock();
30+
$tcp = $this->getMockBuilder('React\Socket\ServerInterface')->getMock();
3131
$tcp->expects($this->once())->method('close');
3232

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

0 commit comments

Comments
 (0)