From patchwork Fri Sep 1 18:03:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 808896 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xkRzd5D5Sz9t2x for ; Sat, 2 Sep 2017 04:07:41 +1000 (AEST) Received: from localhost ([::1]:53097 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnqLz-0001l7-5w for incoming@patchwork.ozlabs.org; Fri, 01 Sep 2017 14:07:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnqIV-00078p-4k for qemu-devel@nongnu.org; Fri, 01 Sep 2017 14:04:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnqIP-0001Z7-Eo for qemu-devel@nongnu.org; Fri, 01 Sep 2017 14:04:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53634) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dnqIP-0001YT-9y for qemu-devel@nongnu.org; Fri, 01 Sep 2017 14:03:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EFF3883DE for ; Fri, 1 Sep 2017 18:03:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5EFF3883DE Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com Received: from red.redhat.com (ovpn-121-149.rdu2.redhat.com [10.10.121.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93229627DE; Fri, 1 Sep 2017 18:03:55 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 1 Sep 2017 13:03:19 -0500 Message-Id: <20170901180340.30009-9-eblake@redhat.com> In-Reply-To: <20170901180340.30009-1-eblake@redhat.com> References: <20170901180340.30009-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 01 Sep 2017 18:03:56 +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 v6 08/29] 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: pbonzini@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 = strlen(buf); + } offset = 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 = g_strdup_vprintf(fmt, ap); - size_t size = 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 = 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);