diff --git a/composer.json b/composer.json index 0385653c..bdd9d502 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "php": ">=5.3.0", "react/dns": "0.4.*|0.3.*", "react/event-loop": "0.4.*|0.3.*", - "react/stream": "0.4.*|0.3.*", + "react/stream": "^0.4.5", "react/promise": "^2.1 || ^1.2", "react/promise-timer": "~1.0" }, @@ -17,6 +17,6 @@ } }, "require-dev": { - "clue/block-react": "~1.0" + "clue/block-react": "^1.1" } } diff --git a/src/SecureStream.php b/src/SecureStream.php deleted file mode 100644 index 5aa879c6..00000000 --- a/src/SecureStream.php +++ /dev/null @@ -1,98 +0,0 @@ -stream = $stream->stream; - $this->decorating = $stream; - $this->loop = $loop; - $that = $this; - - $stream->on('error', function($error) use ($that) { - $that->emit('error', array($error, $that)); - }); - $stream->on('end', function() use ($that) { - $that->emit('end', array($that)); - }); - $stream->on('close', function() use ($that) { - $that->emit('close', array($that)); - }); - $stream->on('drain', function() use ($that) { - $that->emit('drain', array($that)); - }); - - $stream->pause(); - - $this->resume(); - } - - public function handleData($stream) - { - $data = stream_get_contents($stream); - - $this->emit('data', array($data, $this)); - - if (!is_resource($stream) || feof($stream)) { - $this->end(); - } - } - - public function pause() - { - $this->loop->removeReadStream($this->decorating->stream); - } - - public function resume() - { - if ($this->isReadable()) { - $this->loop->addReadStream($this->decorating->stream, array($this, 'handleData')); - } - } - - public function isReadable() - { - return $this->decorating->isReadable(); - } - - public function isWritable() - { - return $this->decorating->isWritable(); - } - - public function write($data) - { - return $this->decorating->write($data); - } - - public function close() - { - return $this->decorating->close(); - } - - public function end($data = null) - { - return $this->decorating->end($data); - } - - public function pipe(WritableStreamInterface $dest, array $options = array()) - { - Util::pipe($this, $dest, $options); - - return $dest; - } -} \ No newline at end of file diff --git a/src/StreamEncryption.php b/src/StreamEncryption.php index 2a76dd0c..e6a37330 100644 --- a/src/StreamEncryption.php +++ b/src/StreamEncryption.php @@ -57,10 +57,6 @@ public function disable(Stream $stream) public function toggle(Stream $stream, $toggle) { - if (__NAMESPACE__ . '\SecureStream' === get_class($stream)) { - $stream = $stream->decorating; - } - // pause actual stream instance to continue operation on raw stream socket $stream->pause(); @@ -89,7 +85,7 @@ public function toggle(Stream $stream, $toggle) $loop->removeReadStream($socket); if ($wrap) { - return new SecureStream($stream, $loop); + $stream->bufferSize = null; } $stream->resume(); diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 87d9d0a4..0568dece 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -13,6 +13,8 @@ class IntegrationTest extends TestCase { + const TIMEOUT = 5.0; + /** @test */ public function gettingStuffFromGoogleShouldWork() { @@ -26,7 +28,7 @@ public function gettingStuffFromGoogleShouldWork() $conn->write("GET / HTTP/1.0\r\n\r\n"); - $response = Block\await(BufferedSink::createPromise($conn), $loop); + $response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT); $this->assertRegExp('#^HTTP/1\.0#', $response); } @@ -52,7 +54,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork() $conn->write("GET / HTTP/1.0\r\n\r\n"); - $response = Block\await(BufferedSink::createPromise($conn), $loop); + $response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT); $this->assertRegExp('#^HTTP/1\.0#', $response); } @@ -78,7 +80,7 @@ public function testSelfSignedRejectsIfVerificationIsEnabled() ); $this->setExpectedException('RuntimeException'); - Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop); + Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop, self::TIMEOUT); } /** @test */ @@ -101,7 +103,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled() ) ); - $conn = Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop); + $conn = Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop, self::TIMEOUT); $conn->close(); } diff --git a/tests/SecureIntegrationTest.php b/tests/SecureIntegrationTest.php index aea710e9..ef85dad3 100644 --- a/tests/SecureIntegrationTest.php +++ b/tests/SecureIntegrationTest.php @@ -15,6 +15,8 @@ class SecureIntegrationTest extends TestCase { + const TIMEOUT = 0.5; + private $portSecure; private $portPlain; @@ -51,7 +53,7 @@ public function tearDown() public function testConnectToServer() { - $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop); + $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT); /* @var $client Stream */ $client->close(); @@ -63,7 +65,7 @@ public function testConnectToServerEmitsConnection() $promiseClient = $this->connector->create('127.0.0.1', $this->portSecure); - list($_, $client) = Block\awaitAll(array($promiseServer, $promiseClient), $this->loop); + list($_, $client) = Block\awaitAll(array($promiseServer, $promiseClient), $this->loop, self::TIMEOUT); /* @var $client Stream */ $client->close(); @@ -79,13 +81,13 @@ public function testSendSmallDataToServerReceivesOneChunk() }); }); - $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop); + $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT); /* @var $client Stream */ $client->write('hello'); // await server to report one "data" event - $data = Block\await($received->promise(), $this->loop); + $data = Block\await($received->promise(), $this->loop, self::TIMEOUT); $client->close(); @@ -105,14 +107,14 @@ public function testSendDataWithEndToServerReceivesAllData() }); }); - $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop); + $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT); /* @var $client Stream */ $data = str_repeat('a', 200000); $client->end($data); // await server to report connection "close" event - $received = Block\await($disconnected->promise(), $this->loop); + $received = Block\await($disconnected->promise(), $this->loop, self::TIMEOUT); $this->assertEquals($data, $received); } @@ -126,7 +128,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData() }); }); - $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop); + $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT); /* @var $client Stream */ $data = str_repeat('d', 200000); @@ -146,12 +148,12 @@ public function testConnectToServerWhichSendsSmallDataReceivesOneChunk() $peer->write('hello'); }); - $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop); + $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT); /* @var $client Stream */ // await client to report one "data" event $receive = $this->createPromiseForEvent($client, 'data', $this->expectCallableOnceWith('hello')); - Block\await($receive, $this->loop); + Block\await($receive, $this->loop, self::TIMEOUT); $client->close(); } @@ -163,11 +165,11 @@ public function testConnectToServerWhichSendsDataWithEndReceivesAllData() $peer->end($data); }); - $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop); + $client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT); /* @var $client Stream */ // await data from client until it closes - $received = Block\await(BufferedSink::createPromise($client), $this->loop); + $received = Block\await(BufferedSink::createPromise($client), $this->loop, self::TIMEOUT); $this->assertEquals($data, $received); } diff --git a/tests/TcpConnectorTest.php b/tests/TcpConnectorTest.php index c48a096d..964297df 100644 --- a/tests/TcpConnectorTest.php +++ b/tests/TcpConnectorTest.php @@ -9,6 +9,8 @@ class TcpConnectorTest extends TestCase { + const TIMEOUT = 0.1; + /** @test */ public function connectionToEmptyPortShouldFail() { @@ -35,7 +37,7 @@ public function connectionToTcpServerShouldSucceed() $connector = new TcpConnector($loop); - $stream = Block\await($connector->create('127.0.0.1', 9999), $loop); + $stream = Block\await($connector->create('127.0.0.1', 9999), $loop, self::TIMEOUT); $this->assertInstanceOf('React\Stream\Stream', $stream); @@ -67,7 +69,7 @@ public function connectionToIp6TcpServerShouldSucceed() $connector = new TcpConnector($loop); - $stream = Block\await($connector->create('::1', 9999), $loop); + $stream = Block\await($connector->create('::1', 9999), $loop, self::TIMEOUT); $this->assertInstanceOf('React\Stream\Stream', $stream);