Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
change size attribute destination, add line attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Apr 25, 2024
1 parent 6b4c443 commit 2ad7d32
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -27,6 +29,10 @@ public function __construct(
$size
);

$this->setLine(
$line
);

$this->setLive(
$live
);
Expand Down Expand Up @@ -81,6 +87,18 @@ public function setSize(
$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;
Expand Down Expand Up @@ -130,20 +148,29 @@ public function start(

$request = fread(
$incoming,
$this->_size
$this->_line
);

$success = true;

$content = '';

do
{
$line = trim(
fread(
$incoming,
$this->_size
$this->_line
)
);

if ($this->_size && mb_strlen($content) > $this->_size)
{
$success = false;

break;
}

if ($line == '.')
{
break;
Expand All @@ -166,6 +193,7 @@ public function start(
{
$response = call_user_func(
$handler,
$success,
$content,
$request,
$connect
Expand Down

0 comments on commit 2ad7d32

Please sign in to comment.