private function handleControl(string $body = null, &$header = null, int $flags = 0): bool
    {
        $header = $body;
        if (is_null($body) || $flags & Relay::PAYLOAD_RAW) {
            // empty or raw prefix
            return true;
        }

        $p = json_decode($body, true);
        if ($p === false) {
            throw new RoadRunnerException("invalid task context, JSON payload is expected");
        }

        // PID negotiation (socket connections only)
        if (!empty($p['pid'])) {
            $this->relay->send(
                sprintf('{"pid":%s}', getmypid()), Relay::PAYLOAD_CONTROL
            );
        }

        // termination request
        if (!empty($p['stop'])) {
            return false;
        }

        // parsed header
        $header = $p;

        return true;
    }