Called when new data received
@return void
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();
        }
    }
24406
public function received()
    {
        $model = $this->noInitModel;
        return $this->likeCondition($model->initDatetime(), $model->receivedAtAttribute, 'not in');
    }
106188
protected function checkLoaded()
    {
        if ($this->isLoaded()) return;

        $this->data   = $this->read();
        $this->loaded = true;
    }
718461
public function onRead()
    {
        if ($this->state === self::STATE_PREHANDSHAKE) {
            if (!$this->handshake()) {
                return;
            }
        }
        if ($this->state === self::STATE_HANDSHAKED) {
            while (($buflen = $this->getInputLength()) >= 2) {
                $first = ord($this->look(1)); // first byte integer (fin, opcode)
                $firstBits = Binary::getbitmap($first);
                $opcode = (int)bindec(substr($firstBits, 4, 4));
                if ($opcode === 0x8) { // CLOSE
                    $this->finish();
                    return;
                }
                $opcodeName = isset(static::$opcodes[$opcode]) ? static::$opcodes[$opcode] : false;
                if (!$opcodeName) {
                    Daemon::log(get_class($this) . ': Undefined opcode ' . $opcode);
                    $this->finish();
                    return;
                }
                if ($this->firstFrameOpcodeName === null) {
                    $this->firstFrameOpcodeName = $opcodeName;
                }
                $second = ord($this->look(1, 1)); // second byte integer (masked, payload length)
                $fin = (bool)($first >> 7);
                $isMasked = (bool)($second >> 7);
                $dataLength = $second & 0x7f;
                $p = 2;
                if ($dataLength === 0x7e) { // 2 bytes-length
                    if ($buflen < $p + 2) {
                        return; // not enough data yet
                    }
                    $dataLength = Binary::bytes2int($this->look(2, $p), false);
                    $p += 2;
                } elseif ($dataLength === 0x7f) { // 8 bytes-length
                    if ($buflen < $p + 8) {
                        return; // not enough data yet
                    }
                    $dataLength = Binary::bytes2int($this->look(8, $p));
                    $p += 8;
                }
                if ($this->pool->maxAllowedPacket <= $dataLength) {
                    // Too big packet
                    Daemon::log(get_class($this) . ': MaxAllowedPacket limit exceeded. Packet size ' . $dataLength . ' bytes when limit ' . $this->pool->maxAllowedPacket . ' bytes');
                    $this->finish();
                    return;
                }
                // Extend buffer size to accommodate all data
                $this->setWatermark(null, $dataLength + 100);
                if ($isMasked) {
                    if ($buflen < $p + 4) {
                        return; // not enough data yet
                    }
                    $mask = $this->look(4, $p);
                    $p += 4;
                }
                if ($buflen < $p + $dataLength) {
                    return; // not enough data yet
                }
                $this->drain($p);
                $data = $this->read($dataLength);
                if ($isMasked) {
                    $data = $this->mask($data, $mask);
                }
                //Daemon::log(Debug::dump(array('ext' => $this->extensions, 'rsv1' => $firstBits[1], 'data' => Debug::exportBytes($data))));
                /*if ($firstBits[1] && in_array('deflate-frame', $this->extensions)) { // deflate frame
                    $data = gzuncompress($data, $this->pool->maxAllowedPacket);
                }*/
                if (!$fin) {
                    $this->framebuf .= $data;
                } else {
                    $this->onFrame($this->framebuf . $data, $this->firstFrameOpcodeName);
                    $this->firstFrameOpcodeName = null;
                    $this->framebuf = '';
                }
            }
        }
    }
788543
public function receive()
    {
        if ($this->isWritable()) {
            throw new \RuntimeException('Cannot read from writable message');
        }

        $this->readable = true;

        while ($content = fread($this->resource, $this->chunkSize)) {
            $this->content .= $content;
            $this->emit('data', [$content]);
            if (strpos($content, $this->getTerminateString()) !== false) {
                $this->emit('end', [$this]);
            }
        }
    }
415980
public function onResultDone()
    {
        $this->rsState = self::RS_STATE_HEADER;
        $this->onResponse->executeOne($this, true);
        $this->checkFree();
        $this->resultRows = [];
        $this->resultFields = [];
    }
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);
    }
930585
protected function onInput($data)
    {
        //Process data here
        foreach ($this->params as $column) {
            if ($this->character_mask) {
                $data[$column] = trim($data[$column], $this->character_mask);
            } else {
                $data[$column] = trim($data[$column]);
            }
        }
        $this->next($data);
    }
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;
    }
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)
101213
public function touch()
    {
        $model = $this->getRelated();

        if (! $model::isIgnoringTouch()) {
            $this->rawUpdate([
                $model->getUpdatedAtColumn() => $model->freshTimestampString(),
            ]);
        }
    }
1060420
public function onRead()
    {
        start:
        if ($this->freed) {
            return;
        }
        if ($this->state === self::STATE_ROOT) {
            if (false === ($hdr = $this->readExact(16))) {
                return; // we do not have a header
            }
            $this->hdr = unpack('Vlen/VreqId/VresponseTo/VopCode', $hdr);
            $this->hdr['plen'] = $this->hdr['len'] - 16;
            $this->setWatermark($this->hdr['plen'], $this->hdr['plen']);
            $this->state = self::STATE_PACKET;
        }
        if ($this->state === self::STATE_PACKET) {
            if (false === ($pct = $this->readExact($this->hdr['plen']))) {
                return; //we do not have a whole packet
            }
            $this->state = self::STATE_ROOT;
            $this->setWatermark(16, 0xFFFFFF);
            if ($this->hdr['opCode'] === Pool::OP_REPLY) {
                $r = unpack('Vflag/VcursorID1/VcursorID2/Voffset/Vlength', mb_orig_substr($pct, 0, 20));
                $r['cursorId'] = mb_orig_substr($pct, 4, 8);
                $id = (int)$this->hdr['responseTo'];
                if (isset($this->requests[$id])) {
                    $req = $this->requests[$id];
                    if (sizeof($req) === 1) { // get more
                        $r['cursorId'] = $req[0];
                    }
                } else {
                    $req = false;
                }
                $flagBits = str_pad(strrev(decbin($r['flag'])), 8, '0', STR_PAD_LEFT);
                $curId = ($r['cursorId'] !== "\x00\x00\x00\x00\x00\x00\x00\x00" ? 'c' . $r['cursorId'] : 'r' . $this->hdr['responseTo']);

                if ($req && isset($req[2]) && ($req[2] === false) && !isset($this->cursors[$curId])) {
                    $cur = new Cursor($curId, $req[0], $this);
                    $this->cursors[$curId] = $cur;
                    $cur->failure = $flagBits[1] === '1';
                    $cur->await = $flagBits[3] === '1';
                    $cur->callback = $req[1];
                    $cur->parseOplog = isset($req[3]) && $req[3];
                    $cur->tailable = isset($req[4]) && $req[4];
                } else {
                    $cur = isset($this->cursors[$curId]) ? $this->cursors[$curId] : false;
                }
                if ($cur && (($r['length'] === 0) || (mb_orig_substr($curId, 0, 1) === 'r'))) {
                    if ($cur->tailable) {
                        if ($cur->finished = ($flagBits[0] === '1')) {
                            $cur->destroy();
                        }
                    } else {
                        $cur->finished = true;
                    }
                }

                $p = 20;
                $items = [];
                while ($p < $this->hdr['plen']) {
                    $dl = unpack('Vlen', mb_orig_substr($pct, $p, 4));
                    $doc = bson_decode(mb_orig_substr($pct, $p, $dl['len']));

                    if ($cur) {
                        if ($cur->parseOplog && isset($doc['ts'])) {
                            $tsdata = unpack('Vsec/Vinc', mb_orig_substr($pct, $p + 8, 8));
                            $doc['ts'] = $tsdata['sec'] . ' ' . $tsdata['inc'];
                        }
                        $cur->items[] = $doc;
                        ++$cur->counter;
                    } else {
                        $items[] = $doc;
                    }
                    $p += $dl['len'];
                }
                $this->setFree(true);
                if (isset($req[2]) && $req[2] && $req[1]) {
                    $req[1](sizeof($items) ? $items[0] : false);

                    if ($cur) {
                        if ($cur instanceof Cursor) {
                            $cur->destroy();
                        } else {
                            unset($this->cursors[$curId]);
                        }
                    }
                } elseif ($cur) {
                    $func = $cur->callback;
                    $func($cur);
                }
                unset($this->requests[$id]);
                $req = null;
            }
        }
        goto start;
    }
615632
protected function broadcast()
    {
        if (function_exists('broadcast')) {
            broadcast(new NotificationPushed($this->push));
        } elseif (function_exists('event')) {
            event(new NotificationPushed($this->push));
        }
    }
383376
public function handleReadEvent()
    {
        $messages = $this->socket->recvmulti(ZMQ::MODE_DONTWAIT);
        if (false !== $messages)
        {
            $this->emit('messages', [ $messages ]);
        }
    }
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');
            }
        }
    }
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]);
                }
            }
        }
    }
771554
public function onConfigUpdated()
    {
        if ($this->xmppclient) {
            $this->xmppclient->config = $this->config;
            $this->xmppclient->onConfigUpdated();
        }
    }