Called when new data received
@return void
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;
    }
1319296
public function onData(string $data)
    {
        $data = trim($data);
        $this->log('->' . $data);
        $chunks = explode(' ', $data);
        $command = $chunks[0];
        unset($chunks[0]);
        $input = '';
        if (count($chunks) > 0) {
            $input = implode(' ', $chunks);
        }
        $input = trim($input);
        if ($this->node->getCommands()->has($command)) {
            $this
                ->node
                ->getCommands()
                ->get($command)
                ->handle($this, $input)
                ->then(function (array $lines) {
                    foreach ($lines as $line) {
                        $this->write($line);
                    }
                });
            return;
        }

        $list = implode(', ', $this->node->getCommands()->keys());
        $this->write(
            '# Unknown command. Try ' . substr_replace($list, ' or ', strrpos($list, ', '), 2)
        );
    }
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);
        }
    }
801105
public function onDataAvailable()
    {
        $this->read();

        while (($frame = $this->reader->consumeFrame($this->readBuffer)) !== null) {
            foreach ($this->awaitCallbacks as $k => $callback) {
                if ($callback($frame) === true) {
                    unset($this->awaitCallbacks[$k]);
                    continue 2; // CONTINUE WHILE LOOP
                }
            }

            if ($frame->channel === 0) {
                $this->onFrameReceived($frame);

            } else {
                if (!isset($this->channels[$frame->channel])) {
                    throw new ClientException(
                        "Received frame #{$frame->type} on closed channel #{$frame->channel}."
                    );
                }

                $this->channels[$frame->channel]->onFrameReceived($frame);
            }
        }
    }
913666
public function onRead()
    {
        if (false === ($pct = $this->readExact($this->lowMark))) {
            return; // not readed yet
        }
        if ($pct === "<policy-file-request/>\x00") {
            if ($this->pool->policyData) {
                $this->write($p = $this->pool->policyData . "\x00");
            } else {
                $this->write("<error/>\x00");
            }
        }
        $this->finish();
    }
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));
                    }
                }
            }
        }
    }
216099
protected function onInput($data)
    {
        //Process data here
        foreach ($this->params as $cName => $cParam) {
            $numberFormat = array_merge($cParam, array("type" => "number"));
            //print_r($numberFormat);
            $from = Utility::format(floor($data[$cName] / $cParam["step"]) * $cParam["step"], $numberFormat);
            $to = Utility::format(floor($data[$cName] / $cParam["step"] + 1) * $cParam["step"], $numberFormat);

            $data[$cName] = Utility::strReplace(
                $cParam["formatString"],
                array(
                    "{from}" => $from,
                    "{to}" => $to,
                )
            );
        }
        $this->next($data);
    }
1181538
public function onRead()
    {
        if ($this->state === self::CONN_STATE_START) {
            if (($ver = $this->readline()) === null) {
                return;
            }
            $this->pool->setAmiVersion($this->addr, $ver);
            $this->state = self::CONN_STATE_GOT_INITIAL_PACKET;
            $this->auth();
        }

        while (($line = $this->readline()) !== null) {
            //Daemon::log('>>> '.$line);
            if ($line === '') {
                $this->instate = self::INPUT_STATE_END_OF_PACKET;
                $packet =& $this->packets[$this->cnt];
                ++$this->cnt;
            } else {
                $this->instate = self::INPUT_STATE_PROCESSING;
                list($header, $value) = Pool::extract($line);
                $this->packets[$this->cnt][$header] = $value;
            }

            if ((int)$this->state === self::CONN_STATE_AUTH) {
                if ($this->instate === self::INPUT_STATE_END_OF_PACKET) {
                    if ($packet['response'] === 'success') {
                        if ($this->state === self::CONN_STATE_CHALLENGE_PACKET_SENT) {
                            if (is_callable($this->onChallenge)) {
                                $func = $this->onChallenge;
                                $func($this, $packet['challenge']);
                            }
                        } else {
                            if ($packet['message'] === 'authentication accepted') {
                                $this->state = self::CONN_STATE_HANDSHAKED_OK;

                                Daemon::$process->log(
                                    __METHOD__ . ': Authentication ok. Connected to ' .
                                    parse_url($this->addr, PHP_URL_HOST)
                                );

                                if ($this->onConnected) {
                                    $this->connected = true;
                                    $this->onConnected->executeAll($this);
                                    $this->onConnected = null;
                                }

                                $this->event('connected');
                            }
                        }
                    } else {
                        $this->state = self::CONN_STATE_HANDSHAKED_ERROR;

                        Daemon::$process->log(
                            __METHOD__ . ': Authentication failed. Connection to ' .
                            parse_url($this->addr, PHP_URL_HOST) . ' failed.'
                        );

                        if ($this->onConnected) {
                            $this->connected = false;
                            $this->onConnected->executeAll($this);
                            $this->onConnected = null;
                        }

                        $this->finish();
                    }

                    $this->packets = [];
                }
            } elseif ($this->state === self::CONN_STATE_HANDSHAKED_OK) {
                if ($this->instate === self::INPUT_STATE_END_OF_PACKET) {
                    // Event
                    if (isset($packet['event']) && !isset($packet['actionid'])) {
                        $this->event('event_' . $packet['event'], $packet);
                        $this->event('event', $packet);
                    } // Response
                    elseif (isset($packet['actionid'])) {
                        $action_id =& $packet['actionid'];

                        if (isset($this->callbacks[$action_id])) {
                            if (isset($this->assertions[$action_id])) {
                                $this->packets[$action_id][] = $packet;

                                $assertations = count(
                                    array_uintersect_uassoc(
                                        $this->assertions[$action_id],
                                        $packet,
                                        'strcasecmp',
                                        'strcasecmp'
                                    )
                                );
                                if ($assertations === count($this->assertions[$action_id])) {
                                    if (is_callable($this->callbacks[$action_id])) {
                                        $this->callbacks[$action_id]($this, $this->packets[$action_id]);
                                        unset($this->callbacks[$action_id]);
                                    }

                                    unset($this->assertions[$action_id]);
                                    unset($this->packets[$action_id]);
                                }
                            } else {
                                if (is_callable($this->callbacks[$action_id])) {
                                    $this->callbacks[$action_id]($this, $packet);
                                    unset($this->callbacks[$action_id]);
                                }
                            }
                        }
                    }

                    unset($packet);
                    unset($this->packets[$this->cnt - 1]);
                }
            }
        }
    }
1315615
public function onRead()
    {
        packet:
        if ($this->state === self::STATE_STANDBY) {
            if ($this->bev->input->length < 4) {
                return;
            }
            $this->pctSize = Binary::bytes2int($this->read(3), true);
            $this->setWatermark($this->pctSize, $this->pctSize);
            $this->state = self::STATE_BODY;
            $this->seq = ord($this->read(1)) + 1;
        }
        /* STATE_BODY */
        $l = $this->bev->input->length;
        if ($l < $this->pctSize) {
            return;
        }
        $this->state = self::STATE_STANDBY;
        $this->setWatermark(4);
        if ($this->phase === 0) {
            $this->phase = self::PHASE_GOT_INIT;
            $this->protover = ord($this->read(1));
            if ($this->protover === 0xFF) { // error
                $fieldCount = $this->protover;
                $this->protover = 0;
                $this->onResponse->push(function ($conn, $result) {
                    if ($conn->onConnected) {
                        $conn->connected = true;
                        $conn->onConnected->executeAll($conn, $result);
                        $conn->onConnected = null;
                    }
                });
                goto field;
            }
            if (($p = $this->search("\x00")) === false) {
                $this->log('nul-terminator of \'serverver\' is not found');
                $this->finish();
                return;
            }
            $this->serverver = $this->read($p);
            $this->drain(1); // drain nul-byte
            $this->threadId = Binary::bytes2int($this->read(4), true);
            $this->scramble = $this->read(8);
            $this->drain(1); // ????

            $this->serverCaps = Binary::bytes2int($this->read(2), true);
            $this->serverLang = ord($this->read(1));
            $this->serverStatus = Binary::bytes2int($this->read(2), true);
            $this->drain(13);
            $restScramble = $this->read(12);
            $this->scramble .= $restScramble;
            $this->drain(1);

            $this->auth();
        } else {
            $fieldCount = ord($this->read(1));
            field:
            if ($fieldCount === 0xFF) {
                // Error packet
                $u = unpack('v', $this->read(2));
                $this->errno = $u[1];
                $state = $this->read(6);
                $this->errmsg = $this->read($this->pctSize - $l + $this->bev->input->length);
                $this->onError();
                $this->errno = 0;
                $this->errmsg = '';
            } elseif ($fieldCount === 0x00) {
                // OK Packet Empty
                if ($this->phase === self::PHASE_AUTH_SENT) {
                    $this->phase = self::PHASE_HANDSHAKED;

                    if ($this->dbname !== '') {
                        $this->query('USE `' . $this->dbname . '`');
                    }
                }

                $this->affectedRows = $this->parseEncodedBinary();

                $this->insertId = $this->parseEncodedBinary();

                $u = unpack('v', $this->read(2));
                $this->serverStatus = $u[1];

                $u = unpack('v', $this->read(2));
                $this->warnCount = $u[1];

                $this->message = $this->read($this->pctSize - $l + $this->bev->input->length);
                $this->onResultDone();
            } elseif ($fieldCount === 0xFE) {
                // EOF Packet
                if ($this->rsState === self::RS_STATE_ROW) {
                    $this->onResultDone();
                } else {
                    ++$this->rsState;
                }
            } else {
                // Data packet
                $this->prependInput(chr($fieldCount));

                if ($this->rsState === self::RS_STATE_HEADER) {
                    // Result Set Header Packet
                    $extra = $this->parseEncodedBinary();
                    $this->rsState = self::RS_STATE_FIELD;
                } elseif ($this->rsState === self::RS_STATE_FIELD) {
                    // Field Packet
                    $field = [
                        'catalog' => $this->parseEncodedString(),
                        'db' => $this->parseEncodedString(),
                        'table' => $this->parseEncodedString(),
                        'org_table' => $this->parseEncodedString(),
                        'name' => $this->parseEncodedString(),
                        'org_name' => $this->parseEncodedString()
                    ];

                    $this->drain(1); // filler

                    $u = unpack('v', $this->read(2));

                    $field['charset'] = $u[1];
                    $u = unpack('V', $this->read(4));
                    $field['length'] = $u[1];

                    $field['type'] = ord($this->read(1));

                    $u = unpack('v', $this->read(2));
                    $field['flags'] = $u[1];

                    $field['decimals'] = ord($this->read(1));

                    $this->resultFields[] = $field;
                } elseif ($this->rsState === self::RS_STATE_ROW) {
                    // Row Packet
                    $row = [];

                    for ($i = 0, $nf = sizeof($this->resultFields); $i < $nf; ++$i) {
                        $row[$this->resultFields[$i]['name']] = $this->parseEncodedString();
                    }

                    $this->resultRows[] = $row;
                }
            }
        }
        if ($this->finished) {
            return;
        }
        $this->drain($this->pctSize - $l + $this->bev->input->length); // drain the rest of packet
        goto packet;
    }
838278
public function postRun(): void {
    if ($this->progress) {
      $this->progress->finish();
      // Progress bar does not print a new-line at the end.
      $this->getOutput()->writeln('');
    }
  }
211148
def _process_incoming_data(self):
        
        while self._running.is_set():
            if self.poller.is_ready:
                self.data_in += self._receive()
                self.data_in = self._on_read_impl(self.data_in)
907204
public function newAction(): void
    {
        try {
            $maximumFileUploadSize = $this->getMaximumFileUploadSize();
        } catch (FilesException $e) {
            $maximumFileUploadSize = null;
        }

        $this->view->assignMultiple([
            'tags' => $this->tagRepository->findAll(),
            'assetCollections' => $this->assetCollectionRepository->findAll(),
            'maximumFileUploadSize' => $maximumFileUploadSize,
            'humanReadableMaximumFileUploadSize' => Files::bytesToSizeString($maximumFileUploadSize)
        ]);
    }
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));
    }
713964
public function onReady()
    {
        $this->connected = true;
        if ($this->onConnected) {
            $this->onConnected->executeAll($this);
            $this->onConnected = null;
        }
    }
591157
public function onReady()
    {
        $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();

        $params = [];
        foreach (range(0, 100) as $i) {
            $params[] = 'myset' . $i;
            $params[] = 'value' . $i;
        }
        $params[] = function ($redis) {
            $params = [
                function ($redis) {
                    D('Count: ' . count($redis->result[1]) . '; Next: ' . $redis->result[0]);
                }
            ];

            $cbEnd = function ($redis, $scan) {
                D('Full scan end!');
            };

            // test 1
            // $this->redis->scan(...$params);

            // test 2
            $this->redis->autoscan('scan', $params, $cbEnd, 50);
        };
        $this->redis->mset(...$params);
    }
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();
        }
    }
31479
@Override
    public final void received () {
        if ( isAsync() && getStatus() == NtStatus.NT_STATUS_PENDING ) {
            synchronized ( this ) {
                notifyAll();
            }
            return;
        }
        this.received = true;
        synchronized ( this ) {
            notifyAll();
        }
    }