private function export(callable $upgrade, string $buffer)
    {
        if ($this->status & self::CLOSED_RDWR || $this->isExported) {
            return;
        }

        $this->clear();
        $this->isExported = true;

        \assert($this->logger->debug("Upgrade {$this->clientAddress}:{$this->clientPort} #{$this->id}") || true);

        try {
            $upgrade(new Internal\DetachedSocket($this, $this->socket, $buffer, $this->options->getChunkSize()));
        } catch (\Throwable $exception) {
            $this->logger->error($exception);
            $this->close();
        }
    }