Write frame to server and expect an matching receipt frame

@param Frame $stompFrame
@return bool
332547
protected function sendFrameExpectingReceipt(Frame $stompFrame)
    {
        $receipt = md5(microtime());
        $stompFrame['receipt'] = $receipt;
        $this->connection->writeFrame($stompFrame);
        return $this->waitForReceipt($receipt);
    }
341276
protected function handleClientCloseFrame(NetworkFrame $frame)
    {
        $this->logger->debug("Client sent close frame, parsing");

        //TODO strict
        $code = $frame->getPayloadPart(0, 2);

        if (!empty($code)) { //Code is optional BUT it can't be 0
            if (!isset($code[1])) { // payload have to be at least 2 bytes
                throw new WebSocketException("Invalid closing payload", DataFrame::CODE_PROTOCOL_ERROR);
            }

            $code = unpack("n", $code);
            $code = $code[1]; //Array dereference on call is allowed from 5.4
            $this->logger->debug("Client disconnected with code: " . $code);

            if (!DataFrame::validateCloseCode($code)) {
                throw new WebSocketException("Invalid close code", DataFrame::CODE_PROTOCOL_ERROR);
            }

            if (!mb_check_encoding($frame->getPayloadPart(2), 'UTF-8')) {
                throw new WebSocketException("Close frame payload is not valid UTF-8",
                    NetworkFrame::CODE_DATA_TYPE_INCONSISTENT);
            }
        }

        $this->logger->debug("Converting client close frame into server close frame");
        $frame->setOpcode(DataFrame::OPCODE_CLOSE);
        $frame->setMasking(false);
        $frame->setPayload(pack("n", DataFrame::CODE_CLOSE_NORMAL) . "Client closed connection");
        $this->pushData($frame);
        $this->disconnect();
    }
21630
function check_page_break(Frame $frame)
    {
        //FIXME: should not need to do this since we're tracking table status in `$this->_in_table`
        $p = $frame;
        $in_table = false;
        while ($p) {
            if ($p->is_table()) { $in_table = true; break; }
            $p = $p->get_parent();
        }
        // Do not split if we have already or if the frame was already
        // pushed to the next page (prevents infinite loops)
        if ($in_table) {
            if ($this->_page_full && $frame->_already_pushed) {
                return false;
            }
        } elseif ($this->_page_full || $frame->_already_pushed) {
            return false;
        }

        //FIXME: work-around for infinite loop due to tables 
        if ($in_table && $frame->_already_pushed) {
            return false;
        }
        $p = $frame;
        do {
            $display = $p->get_style()->display;
            if ($display == "table-row") {
                if ($p->_already_pushed) { return false; }
            }
        } while ($p = $p->get_parent());

        // If the frame is absolute of fixed it shouldn't break
        $p = $frame;
        do {
            if ($p->is_absolute()) {
                return false;
            }

            // FIXME If the row is taller than the page and
            // if it the first of the page, we don't break
            $display = $p->get_style()->display;
            if ($display === "table-row"
                && !$p->get_prev_sibling()
                && $p->get_margin_height() > $this->get_margin_height()
            ) {
                return false;
            }
        } while ($p = $p->get_parent());

        $margin_height = $frame->get_margin_height();

        // Determine the frame's maximum y value
        $max_y = (float)$frame->get_position("y") + $margin_height;

        // If a split is to occur here, then the bottom margins & paddings of all
        // parents of $frame must fit on the page as well:
        $p = $frame->get_parent();
        while ($p) {
            $max_y += $p->get_style()->computed_bottom_spacing();
            $p = $p->get_parent();
        }


        // Check if $frame flows off the page
        if ($max_y <= $this->_bottom_page_margin) {
            // no: do nothing
            return false;
        }

        Helpers::dompdf_debug("page-break", "check_page_break");
        Helpers::dompdf_debug("page-break", "in_table: " . $this->_in_table);

        // yes: determine page break location
        $iter = $frame;
        $flg = false;

        $in_table = $this->_in_table;

        Helpers::dompdf_debug("page-break", "Starting search");
        while ($iter) {
            // echo "\nbacktrack: " .$iter->get_node()->nodeName ." ".spl_object_hash($iter->get_node()). "";
            if ($iter === $this) {
                Helpers::dompdf_debug("page-break", "reached root.");
                // We've reached the root in our search.  Just split at $frame.
                break;
            }

            if ($this->_page_break_allowed($iter)) {
                Helpers::dompdf_debug("page-break", "break allowed, splitting.");
                $iter->split(null, true);
                $this->_page_full = true;
                $this->_in_table = $in_table;
                $frame->_already_pushed = true;

                return true;
            }

            if (!$flg && $next = $iter->get_last_child()) {
                Helpers::dompdf_debug("page-break", "following last child.");

                if ($next->is_table()) {
                    $this->_in_table++;
                }

                $iter = $next;
                continue;
            }

            if ($next = $iter->get_prev_sibling()) {
                Helpers::dompdf_debug("page-break", "following prev sibling.");

                if ($next->is_table() && !$iter->is_table()) {
                    $this->_in_table++;
                } else if (!$next->is_table() && $iter->is_table()) {
                    $this->_in_table--;
                }

                $iter = $next;
                $flg = false;
                continue;
            }

            if ($next = $iter->get_parent()) {
                Helpers::dompdf_debug("page-break", "following parent.");

                if ($iter->is_table()) {
                    $this->_in_table--;
                }

                $iter = $next;
                $flg = true;
                continue;
            }

            break;
        }

        $this->_in_table = $in_table;

        // No valid page break found.  Just break at $frame.
        Helpers::dompdf_debug("page-break", "no valid break found, just splitting.");

        // If we are in a table, backtrack to the nearest top-level table row
        if ($this->_in_table) {
            $iter = $frame;
            while ($iter && $iter->get_style()->display !== "table-row" && $iter->get_style()->display !== 'table-row-group' && $iter->_already_pushed === false) {
                $iter = $iter->get_parent();
            }

            if ($iter) {
                $iter->split(null, true);
            } else {
                return false;
            }
        } else {
            $frame->split(null, true);
        }

        $this->_page_full = true;
        $frame->_already_pushed = true;

        return true;
    }
779639
public static function hasFrame(string $buffer): bool
    {
        $bufferLength = strlen($buffer);
        if ($bufferLength < FCGI::HEADER_LEN) {
            return false;
        }

        $fastInfo = unpack(FCGI::HEADER_FORMAT, $buffer);
        if ($bufferLength < FCGI::HEADER_LEN + $fastInfo['contentLength'] + $fastInfo['paddingLength']) {
            return false;
        }

        return true;
    }
684717
async def handle_frame(self, frame):
        """"""
        if not isinstance(frame, FrameGetVersionConfirmation):
            return False
        self.version = frame.version
        self.success = True
        return True
421340
public function bufferWrite(string $data): Promise
    {
        if ($this->append_after) {
            $this->append_after -= strlen($data);
            if ($this->append_after === 0) {
                $data .= $this->append;
                $this->append = '';
            } elseif ($this->append_after < 0) {
                $this->append_after = 0;
                $this->append = '';

                throw new Exception('Tried to send too much out of frame data, cannot append');
            }
        }

        return $this->write($data);
    }
727740
public function write($sessionid, $sessiondata)
    {
        $adapter = $this->getAdapter();

        $data = [
          'time' => time(),
          'data' => $sessiondata
        ];

        if ($adapter instanceof PostgreSQL) {
            $data['data'] = bin2hex($data['data']);
        }

        $sess = $this->getDbData($sessionid);

        if ($this->disableLog) {
            Log::temporaryDisable('sql');
        }

        if ($sess === null) {
            // the record doesn't exists in database, lets insert it
            $data['id'] = $sessionid;

            try {
                $adapter->insert($this->getTableName(), $data)->exec();
                return true;

            } catch (DbException $e) {
                Log::emergency($e);
                return false;

            } finally {
                if ($this->disableLog) {
                    Log::restoreTemporaryDisablement();
                }

            }

        } else {
            // the record data already exists in db

            try {
                $adapter->update($this->getTableName(), $data)->where('id', $sessionid)->exec();
                return true;

            } catch (DbException $e) {
                Log::emergency($e);
                return false;

            } finally {
                if ($this->disableLog) {
                    Log::restoreTemporaryDisablement();
                }

            }
        }
    }
900489
public function process(Request $request, DelegateInterface $frame)
    {
        \Concrete\Core\Http\Request::setInstance($request);
        $this->app->instance('Concrete\Core\Http\Request', $request);

        return $frame->next($request);
    }
1331231
public function frameCheck(FrameInterface $frame) {
        if (false !== $frame->getRsv1() ||
            false !== $frame->getRsv2() ||
            false !== $frame->getRsv3()
        ) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid reserve code');
        }

        if ($this->checkForMask && !$frame->isMasked()) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an incorrect frame mask');
        }

        $opcode = $frame->getOpcode();

        if ($opcode > 2) {
            if ($frame->getPayloadLength() > 125 || !$frame->isFinal()) {
                return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected a mismatch between final bit and indicated payload length');
            }

            switch ($opcode) {
                case Frame::OP_CLOSE:
                    $closeCode = 0;

                    $bin = $frame->getPayload();

                    if (empty($bin)) {
                        return $this->newCloseFrame(Frame::CLOSE_NORMAL);
                    }

                    if (strlen($bin) === 1) {
                        return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid close code');
                    }

                    if (strlen($bin) >= 2) {
                        list($closeCode) = array_merge(unpack('n*', substr($bin, 0, 2)));
                    }

                    $checker = $this->closeFrameChecker;
                    if (!$checker($closeCode)) {
                        return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid close code');
                    }

                    if (!$this->checkUtf8(substr($bin, 2))) {
                        return $this->newCloseFrame(Frame::CLOSE_BAD_PAYLOAD, 'Ratchet detected an invalid UTF-8 payload in the close reason');
                    }

                    return $frame;
                    break;
                case Frame::OP_PING:
                case Frame::OP_PONG:
                    break;
                default:
                    return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected an invalid OP code');
                    break;
            }

            return $frame;
        }

        if (Frame::OP_CONTINUE === $frame->getOpcode() && 0 === count($this->messageBuffer)) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected the first frame of a message was a continue');
        }

        if (count($this->messageBuffer) > 0 && Frame::OP_CONTINUE !== $frame->getOpcode()) {
            return $this->newCloseFrame(Frame::CLOSE_PROTOCOL, 'Ratchet detected invalid OP code when expecting continue frame');
        }

        return $frame;
    }
1157135
public function writeFromBuffer(\EventBuffer $src, $n)
    {
        if (!isset($this->bev)) {
            return false;
        }
        $this->writing = true;
        return $this->bev->output->appendFrom($src, $n);
    }
672934
public function onMessage(Server $server, Frame $frame)
    {
        $fd = $frame->fd;

        // init fd and coId mapping
        WebSocketContext::setFdToCoId($fd);

        App::trigger(WsEvent::ON_MESSAGE, null, $server, $frame);

        $this->log("received message: {$frame->data} from fd #{$fd}, co ID #" . Coroutine::tid(), [], 'debug');

        /** @see Dispatcher::message() */
        \bean('wsDispatcher')->message($server, $frame);

        // delete coId to fd mapping
        WebSocketContext::delFdByCoId();
        RequestContext::destroy();
    }
434028
protected function handlePongFrame(NetworkFrame $frame)
    {
        if ($this->currentPingFrame === null) {
            $this->logger->warning("Got unsolicited pong packet from $this - ignoring");

            return;
        }

        if ($this->currentPingFrame->getPayload() !== $frame->getPayload()) {
            throw new WebSocketException("Invalid pong payload", DataFrame::CODE_PROTOCOL_ERROR);
        }

        $this->handler->onPong($this, $this->currentPingFrame);
        $this->currentPingFrame = null;
    }
568629
protected function renderTrace(array $frames): WriterContract
    {
        $this->render('<comment>Exception trace:</comment>');
        foreach ($frames as $i => $frame) {
            if ($i > static::VERBOSITY_NORMAL_FRAMES && $this->output->getVerbosity(
                ) < OutputInterface::VERBOSITY_VERBOSE) {
                $this->render('<info>Please use the argument <fg=red>-v</> to see more details.</info>');
                break;
            }

            $file = $frame->getFile();
            $line = $frame->getLine();
            $class = empty($frame->getClass()) ? '' : $frame->getClass().'::';
            $function = $frame->getFunction();
            $args = $this->argumentFormatter->format($frame->getArgs());
            $pos = str_pad((int) $i + 1, 4, ' ');

            $this->render("<comment><fg=cyan>$pos</>$class$function($args)</comment>");
            $this->render("    <fg=green>$file</>:<fg=green>$line</>", false);
        }

        return $this;
    }
286058
public static function dumpMask($frame)
    {
        $width = count($frame);
        for($y=0;$y<$width;$y++) {
            for($x=0;$x<$width;$x++) {
                echo ord($frame[$y][$x]).',';
            }
        }
    }
1091658
protected function onHeartbeatFrame(Frame $frame, array $beats)
    {
        if ($frame->getCommand() === self::FRAME_SERVER_CONNECTED) {
            $this->intervalServer = $beats[1];
            if ($this->intervalClient === null) {
                $this->intervalClient = $this->intervalServer;
            }
        } else {
            $this->intervalClient = $beats[0];
            $this->rememberActivity();
        }
    }
452527
public function onSwooleWSMessage($server, $frame)
    {
        $this->onSwooleWSAllMessage($server, $frame->fd, $frame->data);
    }
1076687
public function send($destination, $msg, array $header = [], $sync = null)
    {
        if (!$msg instanceof Frame) {
            return $this->send($destination, new Frame('SEND', $header, $msg), [], $sync);
        }

        $msg->addHeaders($header);
        $msg['destination'] = $destination;
        return $this->sendFrame($msg, $sync);
    }