Called when new data received.
@return void
347703
public function onRead()
    {
        $seq = ["\xff\xf4\xff\xfd\x06", "\xff\xec", "\x03", "\x04"];
        $finish = false;
        foreach ($seq as $s) {
            if ($this->search($s) !== false) {
                $finish = true;
            }
        }
        while (($line = $this->readline()) !== null) {
            $line = rtrim($line, "\r\n");
            $e = explode(' ', $line, 2);
            $cmd = trim(strtolower($e[0]));
            $arg = isset($e[1]) ? $e[1] : '';

            if ($cmd === 'quit' || $cmd === 'exit') {
                $this->disconnect();
            } elseif (!$this->auth) {
                $this->checkPassword($line);
            } else {
                $this->processCommand($cmd, $arg);
            }
        }

        if ($finish) {
            $this->finish();
        }
    }
1363
protected function onRead()
    {
        start:
        if ($this->getInputLength() < 5) {
            return;
        }
        /* @TODO: refactoring Binary::* to support direct buffer calls */
        $pct = $this->read(4096);
        $h = Binary::getDWord($pct);
        if ($h !== 0xFFFFFFFF) {
            $this->finish();
            return;
        }
        $type = Binary::getChar($pct);
        if (($type === Pool::S2A_INFO) || ($type === Pool::S2A_INFO_SOURCE)) {
            $result = self::parseInfo($pct, $type);
        } elseif ($type === Pool::S2A_PLAYER) {
            $result = self::parsePlayers($pct);
        } elseif ($type === Pool::S2A_SERVERQUERY_GETCHALLENGE) {
            $result = mb_orig_substr($pct, 0, 4);
            $pct = mb_orig_substr($pct, 5);
        } elseif ($type === Pool::S2A_PONG) {
            $result = true;
        } else {
            $result = null;
        }
        $this->onResponse->executeOne($this, $result);
        $this->checkFree();
        goto start;
    }
704452
protected function onInput($data)
    {
        if (is_array($this->params)) {
            foreach ($this->params as $columnName => $columnInfo) {
                if (isset($columnInfo["name"])) {
                    $columnValue = $data[$columnName];
                    unset($data[$columnName]);
                    $data[$columnInfo["name"]] = $columnValue;
                }
            }
        } else {
            foreach ($this->nameMap as $oldName => $newName) {
                $value = $data[$oldName];
                unset($data[$oldName]);
                $data[$newName] = $value;
            }
        }
        $this->next($data);
    }
161382
protected function onInputEnd()
    {
        foreach ($this->container[0]["data"] as $key => $rows) {
            if (isset($this->container[1]["data"][$key])) {
                foreach ($rows as $first) {
                    foreach ($this->container[1]["data"][$key] as $second) {
                        $this->next(array_merge($first, $second));
                    }
                }
            }
        }
    }
24406
public function received()
    {
        $model = $this->noInitModel;
        return $this->likeCondition($model->initDatetime(), $model->receivedAtAttribute, 'not in');
    }
1084418
public function onReady()
    {
        if ($this->pool->identd) {
            /** @noinspection PhpParamsInspection */
            $this->getSocketName();
            $this->pool->identd->registerPair($this->locAddr, $this->locPort, ['UNIX', $this->user]);
        }
        list($this->nick, $this->realname) = explode('/', $this->path . '/John Doe');
        $this->command('USER', $this->user, 0, '*', $this->realname);
        $this->command('NICK', $this->nick);
        if (mb_orig_strlen($this->password)) {
            $this->message('NickServ', 'IDENTIFY ' . $this->password);
        }
    }
488326
public function onRead()
    {
        while (($line = $this->readline()) !== null) {
            if ($line === '') {
                continue;
            }
            if (mb_orig_strlen($line) > 512) {
                Daemon::$process->log('IRCClientConnection error: buffer overflow.');
                $this->finish();
                return;
            }
            $line = mb_orig_substr($line, 0, -mb_orig_strlen($this->EOL));
            $p = mb_orig_strpos($line, ' :', 1);
            $max = $p !== false ? substr_count($line, "\x20", 0, $p + 1) + 1 : 18;
            $e = explode("\x20", $line, $max);
            $i = 0;
            $from = IRC::parseUsermask($e[$i]{0} === ':' ? mb_orig_substr($e[$i++], 1) : null);
            $cmd = $e[$i++];
            $args = [];

            for ($s = min(sizeof($e), 14); $i < $s; ++$i) {
                if ($e[$i][0] === ':') {
                    $args[] = mb_orig_substr($e[$i], 1);
                    break;
                }
                $args[] = $e[$i];
            }

            if (ctype_digit($cmd)) {
                $code = (int)$cmd;
                $cmd = isset(IRC::$codes[$code]) ? IRC::$codes[$code] : $code;
            }
            $this->lastLine = $line;
            $this->onCommand($from, $cmd, $args);
        }
        if (mb_orig_strlen($this->buf) > 512) {
            Daemon::$process->log('IRCClientConnection error: buffer overflow.');
            $this->finish();
        }
    }
106188
protected function checkLoaded()
    {
        if ($this->isLoaded()) return;

        $this->data   = $this->read();
        $this->loaded = true;
    }
1118466
public function onRead()
    {
        start:
        if ($this->state === self::STATE_ROOT) {
            $header = $this->readExact(8);

            if ($header === false) {
                return;
            }

            $this->header = unpack('Cver/Ctype/nreqid/nconlen/Cpadlen/Creserved', $header);

            if ($this->header['conlen'] > 0) {
                $this->setWatermark($this->header['conlen'], $this->header['conlen']);
            }
            $type = $this->header['type'];
            $this->header['ttype'] = isset(self::$requestTypes[$type]) ? self::$requestTypes[$type] : $type;
            $rid = $this->header['reqid'];
            $this->state = self::STATE_CONTENT;
        } else {
            $type = $this->header['type'];
            $rid = $this->header['reqid'];
        }
        if ($this->state === self::STATE_CONTENT) {
            $this->content = $this->readExact($this->header['conlen']);

            if ($this->content === false) {
                $this->setWatermark($this->header['conlen'], $this->header['conlen']);
                return;
            }

            if ($this->header['padlen'] > 0) {
                $this->setWatermark($this->header['padlen'], $this->header['padlen']);
            }

            $this->state = self::STATE_PADDING;
        }

        if ($this->state === self::STATE_PADDING) {
            $pad = $this->readExact($this->header['padlen']);

            if ($pad === false) {
                return;
            }
        }
        $this->setWatermark(8, 0xFFFFFF);
        $this->state = self::STATE_ROOT;

//        /*Daemon::log('[DEBUG] FastCGI-record ' . $this->header['ttype'] . '). Request ID: ' . $rid
//                . '. Content length: ' . $this->header['conlen'] . ' (' . mb_orig_strlen($this->content) . ') Padding length: ' . $this->header['padlen']
//                . ' (' . mb_orig_strlen($pad) . ')');*/

        if ($type === self::FCGI_BEGIN_REQUEST) {
            $u = unpack('nrole/Cflags', $this->content);

            $req = new \stdClass();
            $req->attrs = new \stdClass;
            $req->attrs->request = [];
            $req->attrs->get = [];
            $req->attrs->post = [];
            $req->attrs->cookie = [];
            $req->attrs->server = [];
            $req->attrs->files = [];
            $req->attrs->session = null;
            $req->attrs->role = self::$roles[$u['role']];
            $req->attrs->flags = $u['flags'];
            $req->attrs->id = $this->header['reqid'];
            $req->attrs->paramsDone = false;
            $req->attrs->inputDone = false;
            $req->attrs->input = new \PHPDaemon\HTTPRequest\Input();
            $req->attrs->chunked = false;
            $req->attrs->noHttpVer = true;
            $req->queueId = $rid;
            $this->requests[$rid] = $req;
        } elseif (isset($this->requests[$rid])) {
            $req = $this->requests[$rid];
        } else {
            Daemon::log('Unexpected FastCGI-record #' . $this->header['type'] . ' (' . $this->header['ttype'] . '). Request ID: ' . $rid . '.');
            return;
        }

        if ($type === self::FCGI_ABORT_REQUEST) {
            $req->abort();
        } elseif ($type === self::FCGI_PARAMS) {
            if ($this->content === '') {
                if (!isset($req->attrs->server['REQUEST_TIME'])) {
                    $req->attrs->server['REQUEST_TIME'] = time();
                }
                if (!isset($req->attrs->server['REQUEST_TIME_FLOAT'])) {
                    $req->attrs->server['REQUEST_TIME_FLOAT'] = microtime(true);
                }
                $req->attrs->paramsDone = true;

                $req = Daemon::$appResolver->getRequest($req, $this);

                if ($req instanceof \stdClass) {
                    $this->endRequest($req, 0, 0);
                    unset($this->requests[$rid]);
                } else {
                    if ($this->pool->config->sendfile->value
                        && (
                            !$this->pool->config->sendfileonlybycommand->value
                            || isset($req->attrs->server['USE_SENDFILE'])
                        )
                        && !isset($req->attrs->server['DONT_USE_SENDFILE'])
                    ) {
                        $fn = tempnam(
                            $this->pool->config->sendfiledir->value,
                            $this->pool->config->sendfileprefix->value
                        );

                        $req->sendfp = fopen($fn, 'wb');
                        $req->header('X-Sendfile: ' . $fn);
                    }

                    $this->requests[$rid] = $req;

                    $req->callInit();
                }
            } else {
                $p = 0;

                while ($p < $this->header['conlen']) {
                    if (($namelen = ord($this->content{$p})) < 128) {
                        ++$p;
                    } else {
                        $u = unpack(
                            'Nlen',
                            chr(ord($this->content{$p}) & 0x7f) . mb_orig_substr($this->content, $p + 1, 3)
                        );
                        $namelen = $u['len'];
                        $p += 4;
                    }

                    if (($vlen = ord($this->content{$p})) < 128) {
                        ++$p;
                    } else {
                        $u = unpack(
                            'Nlen',
                            chr(ord($this->content{$p}) & 0x7f) . mb_orig_substr($this->content, $p + 1, 3)
                        );
                        $vlen = $u['len'];
                        $p += 4;
                    }

                    $req->attrs->server[mb_orig_substr($this->content, $p, $namelen)] = mb_orig_substr(
                        $this->content,
                        $p + $namelen,
                        $vlen
                    );
                    $p += $namelen + $vlen;
                }
            }
        } elseif ($type === self::FCGI_STDIN) {
            if (!$req->attrs->input) {
                goto start;
            }
            if ($this->content === '') {
                $req->attrs->input->sendEOF();
            } else {
                $req->attrs->input->readFromString($this->content);
            }
        }

        if ($req->attrs->inputDone && $req->attrs->paramsDone) {
            $order = $this->pool->variablesOrder ?: 'GPC';
            for ($i = 0, $s = mb_orig_strlen($order); $i < $s; ++$i) {
                $char = $order[$i];

                if ($char === 'G' && is_array($req->attrs->get)) {
                    $req->attrs->request += $req->attrs->get;
                } elseif ($char === 'P' && is_array($req->attrs->post)) {
                    $req->attrs->request += $req->attrs->post;
                } elseif ($char === 'C' && is_array($req->attrs->cookie)) {
                    $req->attrs->request += $req->attrs->cookie;
                }
            }

            Daemon::$process->timeLastActivity = time();
        }
        goto start;
    }
25966
public function onContentLoading()
    {
        $this->triggerEvent(self::API_VERSION_0_9, 'before_load_content', array(&$this->requestFile));
        $this->triggerEvent(self::API_VERSION_1_0, 'onContentLoading', array(&$this->requestFile));
    }
577052
protected function onRead()
    {
        while (($line = $this->readline()) !== null) {
            $e = explode(' , ', $line);
            if ((sizeof($e) !== 2) || !ctype_digit($e[0]) || !ctype_digit($e[1])) {
                $this->writeln($line . ' : ERROR : INVALID-PORT');
                $this->finish();
                return;
            }
            $local = (int)$e[0];
            $foreign = (int)$e[1];
            if ($user = $this->pool->findPair($local, $foreign)) {
                $this->writeln($line . ' : USERID : ' . $user);
            } else {
                $this->writeln($line . ' : ERROR : NO-USER');
            }
        }
    }
1181056
protected function processMasterSocket(): void
    {
        $new = null;

        try {
            $new = $this->socket->accept();
        } catch (Exception $e) {
            $this->logger->error('Socket error: {exception}', [
                'exception' => $e,
            ]);
            return;
        }

        $connection = $this->createConnection($new);
        $this->server->notify(Server::EVENT_SOCKET_CONNECT, [$new, $connection]);
    }
697341
public function touch()
    {
        $key = $this->getRelated()->getKeyName();

        $columns = $this->getRelatedFreshUpdate();

        $ids = $this->getRelatedIds();

        if (count($ids) > 0) {
            $this->getRelated()->newQuery()->whereIn($key, $ids)->update($columns);
        }
    }
496331
protected function onInput($data)
    {
        $ndata = array();
        foreach ($this->params as $colname) {
            if (isset($data[$colname])) {
                $ndata[$colname] = $data[$colname];
            }
        }

        $this->next($ndata);
    }
896418
protected function onInput($data)
    {
        $func = $this->params;

        $data = $func($data);
        if ($data) {
            $this->next($data);
        }
    }
1149789
public function onReady()
    {
        parent::onReady();
        $this->WS = \PHPDaemon\Servers\WebSocket\Pool::getInstance($this->config->wssname->value, false);
    }
778191
public function receiveData(string $data): void
    {
        $chunkSize = null;

        while ($data) {
            $frame = $this->getReceivingFrame();

            $remaining = $frame->getRemainingData();

            if ($remaining === null) {
                $chunkSize = 2;
            } elseif ($remaining > 0) {
                $chunkSize = $remaining;
            }

            $chunkSize = min(strlen($data), $chunkSize);
            $chunk = substr($data, 0, $chunkSize);
            $data = substr($data, $chunkSize);

            $frame->receiveData($chunk);
        }
    }