qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 25/36] qtest: Change qmp_fd_send() to drop varags


From: Eric Blake
Subject: [Qemu-devel] [PATCH 25/36] qtest: Change qmp_fd_send() to drop varags
Date: Wed, 30 Nov 2016 13:44:43 -0600

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 <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]