public function onReadable($watcherId, $socket, Rfc6455Client $client)
{
$data = @fread($socket, 8192);
if ($data != "") {
$client->lastReadAt = $this->now;
$client->bytesRead += \strlen($data);
$client->capacity -= \strlen($data);
if ($client->capacity < $this->maxBytesPerMinute / 2) {
$this->lowCapacityClients[$client->id] = $client;
if ($client->capacity <= 0) {
\Amp\disable($watcherId);
}
}
$frames = $client->parser->send($data);
$client->framesRead += $frames;
$client->framesLastSecond += $frames;
if ($client->framesLastSecond > $this->maxFramesPerSecond / 2) {
if ($client->framesLastSecond > $this->maxFramesPerSecond * 1.5) {
\Amp\disable($watcherId);
// aka tiny frame DoS prevention
}
$this->highFramesPerSecondClients[$client->id] = $client;
}
} elseif (!is_resource($socket) || @feof($socket)) {
if (!$client->closedAt) {
$client->closedAt = $this->now;
$code = Code::ABNORMAL_CLOSE;
$reason = "Client closed underlying TCP connection";
resolve($this->tryAppOnClose($client->id, $code, $reason));
} else {
unset($this->closeTimeouts[$client->id]);
}
$this->unloadClient($client);
}
}