Received: from eggs.gnu.org ([2001:4830:134:3::10]:35694) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cCAor-0003yi-O0 for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cCAoq-00021a-QS for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60096) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cCAoq-00021E-Hu for qemu-devel@nongnu.org; Wed, 30 Nov 2016 14:45:28 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3C6064D82 for ; Wed, 30 Nov 2016 19:45:27 +0000 (UTC) From: Eric Blake Date: Wed, 30 Nov 2016 13:44:43 -0600 Message-Id: <1480535094-23831-26-git-send-email-eblake@redhat.com> In-Reply-To: <1480535094-23831-1-git-send-email-eblake@redhat.com> References: <1480535094-23831-1-git-send-email-eblake@redhat.com> Subject: [Qemu-devel] [PATCH 25/36] qtest: Change qmp_fd_send() to drop varags List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com, pbonzini@redhat.com No external clients were using qmp_fd_sendv(). Making it static lets us refactor the public qmp_fd_send() to take the final string to send over the wire, rather than a dynamic JSON string that has to be parsed into QObject and back out again. Note that the refactoring switches roles: previously, qmp_fd_send() called qmp_fd_sendv(), now the dependence is in the opposite direction. Also, we no longer need to cater to a leading 0xff byte: the only client (test-qga) is already sending a direct string. Signed-off-by: Eric Blake --- tests/libqtest.h | 3 +-- tests/libqtest.c | 33 ++++++++++++--------------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/tests/libqtest.h b/tests/libqtest.h index 0adf880..1f640c0 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -925,8 +925,7 @@ static inline int64_t clock_set(int64_t val) } QDict *qmp_fd_receive(int fd); -void qmp_fd_sendv(int fd, const char *fmt, va_list ap); -void qmp_fd_send(int fd, const char *fmt, ...); +void qmp_fd_send(int fd, const char *msg); QDict *qmp_fd(int fd, const char *msg); #endif diff --git a/tests/libqtest.c b/tests/libqtest.c index b5b9f01..555d0c4 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -425,19 +425,11 @@ QDict *qtest_qmp_receive(QTestState *s) * in the case that they choose to discard all replies up until * a particular EVENT is received. */ -void qmp_fd_sendv(int fd, const char *fmt, va_list ap) +static void qmp_fd_sendv(int fd, const char *fmt, va_list ap) { va_list ap_copy; QObject *qobj; - /* qobject_from_jsonv() silently eats leading 0xff as invalid - * JSON, but we want to test sending them over the wire to force - * resyncs */ - if (*fmt == '\377') { - socket_send(fd, fmt, 1); - fmt++; - } - /* Going through qobject ensures we escape strings properly. * This seemingly unnecessary copy is required in case va_list * is an array type. @@ -448,16 +440,10 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap) /* No need to send anything for an empty QObject. */ if (qobj) { - int log = getenv("QTEST_LOG") != NULL; QString *qstr = qobject_to_json(qobj); const char *str = qstring_get_str(qstr); - size_t size = qstring_get_length(qstr); - if (log) { - fprintf(stderr, "%s", str); - } - /* Send QMP request */ - socket_send(fd, str, size); + qmp_fd_send(fd, str); QDECREF(qstr); qobject_decref(qobj); @@ -484,13 +470,18 @@ QDict *qmp_fd(int fd, const char *msg) return qmp_fd_receive(fd); } -void qmp_fd_send(int fd, const char *fmt, ...) +void qmp_fd_send(int fd, const char *msg) { - va_list ap; + /* No need to send anything for the empty message. */ + if (*msg) { + int log = getenv("QTEST_LOG") != NULL; - va_start(ap, fmt); - qmp_fd_sendv(fd, fmt, ap); - va_end(ap); + if (log) { + fprintf(stderr, "%s", msg); + } + /* Send QMP request */ + socket_send(fd, msg, strlen(msg)); + } } QDict *qtest_qmp(QTestState *s, const char *fmt, ...) -- 2.7.4