From nobody Mon Feb 9 01:30:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1503091070387177.14866416059715; Fri, 18 Aug 2017 14:17:50 -0700 (PDT) Received: from localhost ([::1]:34032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dioeK-00089M-0Q for importer@patchew.org; Fri, 18 Aug 2017 17:17:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1diocQ-0006rm-Rl for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1diocP-0000bm-P2 for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1diocP-0000Zn-FB for qemu-devel@nongnu.org; Fri, 18 Aug 2017 17:15:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E9C23B98 for ; Fri, 18 Aug 2017 21:15:48 +0000 (UTC) Received: from red.redhat.com (ovpn-122-167.rdu2.redhat.com [10.10.122.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id A335260179; Fri, 18 Aug 2017 21:15:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8E9C23B98 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 18 Aug 2017 16:15:33 -0500 Message-Id: <20170818211542.5380-5-eblake@redhat.com> In-Reply-To: <20170818211542.5380-1-eblake@redhat.com> References: <20170818211542.5380-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 18 Aug 2017 21:15:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 04/13] libqtest: Let socket_send() compute length X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rather than make multiple callers call strlen(), it's easier if socket_send() itself can compute a length via strlen() if none was provided (caller passes -1). Callers that can get at the length more efficiently are left that way. Signed-off-by: Eric Blake --- tests/libqtest.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/libqtest.c b/tests/libqtest.c index 3f956f09fc..a6ce21d7f9 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -251,10 +251,13 @@ void qtest_quit(QTestState *s) g_free(s); } -static void socket_send(int fd, const char *buf, size_t size) +static void socket_send(int fd, const char *buf, ssize_t size) { size_t offset; + if (size < 0) { + size =3D strlen(buf); + } offset =3D 0; while (offset < size) { ssize_t len; @@ -274,9 +277,8 @@ static void socket_send(int fd, const char *buf, size_t= size) static void socket_sendf(int fd, const char *fmt, va_list ap) { gchar *str =3D g_strdup_vprintf(fmt, ap); - size_t size =3D strlen(str); - socket_send(fd, str, size); + socket_send(fd, str, -1); g_free(str); } @@ -858,7 +860,7 @@ void qtest_bufwrite(QTestState *s, uint64_t addr, const= void *data, size_t size) bdata =3D g_base64_encode(data, size); qtest_sendf(s, "b64write 0x%" PRIx64 " 0x%zx ", addr, size); - socket_send(s->fd, bdata, strlen(bdata)); + socket_send(s->fd, bdata, -1); socket_send(s->fd, "\n", 1); qtest_rsp(s, 0); g_free(bdata); --=20 2.13.5