From 2ad7d32751c4d96a2120a33760cc35057f0488ab Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 25 Apr 2024 07:00:50 +0300 Subject: [PATCH] change size attribute destination, add line attribute --- src/Server.php | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Server.php b/src/Server.php index a32dc45..0ad3696 100644 --- a/src/Server.php +++ b/src/Server.php @@ -7,12 +7,14 @@ class Server private string $_host; private int $_port; private int $_size; + private int $_line; private bool $_live; public function __construct( string $host = '127.0.0.1', int $port = 1915, - int $size = 1024, + int $size = 0, + int $line = 1024, bool $live = true ) { $this->setHost( @@ -27,6 +29,10 @@ class Server $size ); + $this->setLine( + $line + ); + $this->setLive( $live ); @@ -81,6 +87,18 @@ class Server $this->_size = $value; } + public function getLine(): int + { + return $this->_line; + } + + public function setLine( + int $value + ): void + { + $this->_line = $value; + } + public function getLive(): bool { return $this->_live; @@ -130,9 +148,11 @@ class Server $request = fread( $incoming, - $this->_size + $this->_line ); + $success = true; + $content = ''; do @@ -140,10 +160,17 @@ class Server $line = trim( fread( $incoming, - $this->_size + $this->_line ) ); + if ($this->_size && mb_strlen($content) > $this->_size) + { + $success = false; + + break; + } + if ($line == '.') { break; @@ -166,6 +193,7 @@ class Server { $response = call_user_func( $handler, + $success, $content, $request, $connect