aboutsummaryrefslogtreecommitdiff
path: root/util/qemu-sockets.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2017-03-30 19:43:15 +0200
committerMax Reitz <mreitz@redhat.com>2017-04-03 17:11:39 +0200
commit216411b83967ae19e3c9c520e13ceb8bb383890c (patch)
tree6b6a983a5e3aeadcf39ed6180287607ff3478d3b /util/qemu-sockets.c
parent8bc0673f6dc2485b46da6de8204aaca2a711acea (diff)
sockets: New helper socket_address_crumple()
SocketAddress is a simple union, and simple unions are awkward: they have their variant members wrapped in a "data" object on the wire, and require additional indirections in C. I intend to limit its use to existing external interfaces. New ones should use SocketAddressFlat. I further intend to convert all internal interfaces to SocketAddressFlat. This helper should go away then. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-id: 1490895797-29094-8-git-send-email-armbru@redhat.com Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'util/qemu-sockets.c')
-rw-r--r--util/qemu-sockets.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 4ae37bd2a2..21442c30dc 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -25,6 +25,7 @@
#include "qapi/error.h"
#include "qemu/sockets.h"
#include "qemu/main-loop.h"
+#include "qapi/clone-visitor.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/qobject-output-visitor.h"
#include "qapi-visit.h"
@@ -1341,3 +1342,34 @@ char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
}
return buf;
}
+
+SocketAddress *socket_address_crumple(SocketAddressFlat *addr_flat)
+{
+ SocketAddress *addr = g_new(SocketAddress, 1);
+
+ switch (addr_flat->type) {
+ case SOCKET_ADDRESS_FLAT_TYPE_INET:
+ addr->type = SOCKET_ADDRESS_KIND_INET;
+ addr->u.inet.data = QAPI_CLONE(InetSocketAddress,
+ &addr_flat->u.inet);
+ break;
+ case SOCKET_ADDRESS_FLAT_TYPE_UNIX:
+ addr->type = SOCKET_ADDRESS_KIND_UNIX;
+ addr->u.q_unix.data = QAPI_CLONE(UnixSocketAddress,
+ &addr_flat->u.q_unix);
+ break;
+ case SOCKET_ADDRESS_FLAT_TYPE_VSOCK:
+ addr->type = SOCKET_ADDRESS_KIND_VSOCK;
+ addr->u.vsock.data = QAPI_CLONE(VsockSocketAddress,
+ &addr_flat->u.vsock);
+ break;
+ case SOCKET_ADDRESS_FLAT_TYPE_FD:
+ addr->type = SOCKET_ADDRESS_KIND_FD;
+ addr->u.fd.data = QAPI_CLONE(String, &addr_flat->u.fd);
+ break;
+ default:
+ abort();
+ }
+
+ return addr;
+}