From b2b6b0e6c30ea7d7c20b341b7fb593b4f0d17420 Mon Sep 17 00:00:00 2001 From: cclilshy Date: Fri, 25 Oct 2024 10:52:04 +0800 Subject: [PATCH] Update composer.json --- composer.json | 2 +- src/Server/Connection.php | 8 +++++++- src/Server/Server.php | 4 +--- tests/HttpTest.php | 4 ++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index a959d32..06fcd83 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "cloudtay/ripple-http", - "version": "v0.1", + "version": "v0.2", "license": "MIT", "authors": [ { diff --git a/src/Server/Connection.php b/src/Server/Connection.php index 29d033a..d4dd694 100644 --- a/src/Server/Connection.php +++ b/src/Server/Connection.php @@ -143,7 +143,13 @@ public function listen(Closure $builder): void }); $this->stream->onReadable(function (SocketStream $stream) use ($builder) { - $content = $stream->read(8192); + try { + $content = $stream->read(8192); + } catch (Throwable) { + $stream->close(); + return; + } + if ($content === '') { if ($stream->eof()) { $stream->close(); diff --git a/src/Server/Server.php b/src/Server/Server.php index 2b30845..5c6fc46 100644 --- a/src/Server/Server.php +++ b/src/Server/Server.php @@ -113,9 +113,7 @@ public function __construct(string $address, mixed $context = null) public function listen(): void { $this->server->onReadable(function (SocketStream $stream) { - try { - $client = $stream->accept(); - } catch (Throwable) { + if (!$client = $stream->accept()) { return; } diff --git a/tests/HttpTest.php b/tests/HttpTest.php index c99d7b1..f2ee4b2 100644 --- a/tests/HttpTest.php +++ b/tests/HttpTest.php @@ -6,9 +6,9 @@ use GuzzleHttp\Exception\GuzzleException; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; -use Ripple\Coroutine\Promise; use Ripple\App\Http\Server\Request; -use Psc\Utils\Output; +use Ripple\Coroutine\Promise; +use Ripple\Utils\Output; use Symfony\Component\HttpFoundation\File\UploadedFile; use function Co\async;