sockets: Use new QAPI cloning
Rather than rolling our own clone via an expensive conversion in and back out of QObject, use the new clone visitor. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1465490926-28625-15-git-send-email-eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
a15fcc3cf6
commit
37f9e0a2b6
@ -159,7 +159,7 @@ typedef int (*QIOTaskWorker)(QIOTask *task,
|
|||||||
* QIOTask *task;
|
* QIOTask *task;
|
||||||
* SocketAddress *addrCopy;
|
* SocketAddress *addrCopy;
|
||||||
*
|
*
|
||||||
* qapi_copy_SocketAddress(&addrCopy, addr);
|
* addrCopy = QAPI_CLONE(SocketAddress, addr);
|
||||||
* task = qio_task_new(OBJECT(obj), func, opaque, notify);
|
* task = qio_task_new(OBJECT(obj), func, opaque, notify);
|
||||||
*
|
*
|
||||||
* qio_task_run_in_thread(task, myobject_listen_worker,
|
* qio_task_run_in_thread(task, myobject_listen_worker,
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
#ifndef QAPI_CLONE_VISITOR_H
|
#ifndef QAPI_CLONE_VISITOR_H
|
||||||
#define QAPI_CLONE_VISITOR_H
|
#define QAPI_CLONE_VISITOR_H
|
||||||
|
|
||||||
|
#include "qemu/typedefs.h"
|
||||||
#include "qapi/visitor.h"
|
#include "qapi/visitor.h"
|
||||||
|
#include "qapi-visit.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The clone visitor is for direct use only by the QAPI_CLONE() macro;
|
* The clone visitor is for direct use only by the QAPI_CLONE() macro;
|
||||||
|
@ -107,10 +107,6 @@ SocketAddress *socket_local_address(int fd, Error **errp);
|
|||||||
*/
|
*/
|
||||||
SocketAddress *socket_remote_address(int fd, Error **errp);
|
SocketAddress *socket_remote_address(int fd, Error **errp);
|
||||||
|
|
||||||
|
|
||||||
void qapi_copy_SocketAddress(SocketAddress **p_dest,
|
|
||||||
SocketAddress *src);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* socket_address_to_string:
|
* socket_address_to_string:
|
||||||
* @addr: the socket address struct
|
* @addr: the socket address struct
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "io/channel-socket.h"
|
#include "io/channel-socket.h"
|
||||||
#include "io/channel-watch.h"
|
#include "io/channel-watch.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
#include "qapi/clone-visitor.h"
|
||||||
|
|
||||||
#define SOCKET_MAX_FDS 16
|
#define SOCKET_MAX_FDS 16
|
||||||
|
|
||||||
@ -189,7 +190,7 @@ void qio_channel_socket_connect_async(QIOChannelSocket *ioc,
|
|||||||
OBJECT(ioc), callback, opaque, destroy);
|
OBJECT(ioc), callback, opaque, destroy);
|
||||||
SocketAddress *addrCopy;
|
SocketAddress *addrCopy;
|
||||||
|
|
||||||
qapi_copy_SocketAddress(&addrCopy, addr);
|
addrCopy = QAPI_CLONE(SocketAddress, addr);
|
||||||
|
|
||||||
/* socket_connect() does a non-blocking connect(), but it
|
/* socket_connect() does a non-blocking connect(), but it
|
||||||
* still blocks in DNS lookups, so we must use a thread */
|
* still blocks in DNS lookups, so we must use a thread */
|
||||||
@ -251,7 +252,7 @@ void qio_channel_socket_listen_async(QIOChannelSocket *ioc,
|
|||||||
OBJECT(ioc), callback, opaque, destroy);
|
OBJECT(ioc), callback, opaque, destroy);
|
||||||
SocketAddress *addrCopy;
|
SocketAddress *addrCopy;
|
||||||
|
|
||||||
qapi_copy_SocketAddress(&addrCopy, addr);
|
addrCopy = QAPI_CLONE(SocketAddress, addr);
|
||||||
|
|
||||||
/* socket_listen() blocks in DNS lookups, so we must use a thread */
|
/* socket_listen() blocks in DNS lookups, so we must use a thread */
|
||||||
trace_qio_channel_socket_listen_async(ioc, addr);
|
trace_qio_channel_socket_listen_async(ioc, addr);
|
||||||
@ -331,8 +332,8 @@ void qio_channel_socket_dgram_async(QIOChannelSocket *ioc,
|
|||||||
struct QIOChannelSocketDGramWorkerData *data = g_new0(
|
struct QIOChannelSocketDGramWorkerData *data = g_new0(
|
||||||
struct QIOChannelSocketDGramWorkerData, 1);
|
struct QIOChannelSocketDGramWorkerData, 1);
|
||||||
|
|
||||||
qapi_copy_SocketAddress(&data->localAddr, localAddr);
|
data->localAddr = QAPI_CLONE(SocketAddress, localAddr);
|
||||||
qapi_copy_SocketAddress(&data->remoteAddr, remoteAddr);
|
data->remoteAddr = QAPI_CLONE(SocketAddress, remoteAddr);
|
||||||
|
|
||||||
trace_qio_channel_socket_dgram_async(ioc, localAddr, remoteAddr);
|
trace_qio_channel_socket_dgram_async(ioc, localAddr, remoteAddr);
|
||||||
qio_task_run_in_thread(task,
|
qio_task_run_in_thread(task,
|
||||||
|
@ -32,8 +32,7 @@
|
|||||||
#include "sysemu/char.h"
|
#include "sysemu/char.h"
|
||||||
#include "hw/usb.h"
|
#include "hw/usb.h"
|
||||||
#include "qmp-commands.h"
|
#include "qmp-commands.h"
|
||||||
#include "qapi/qmp-input-visitor.h"
|
#include "qapi/clone-visitor.h"
|
||||||
#include "qapi/qmp-output-visitor.h"
|
|
||||||
#include "qapi-visit.h"
|
#include "qapi-visit.h"
|
||||||
#include "qemu/base64.h"
|
#include "qemu/base64.h"
|
||||||
#include "io/channel-socket.h"
|
#include "io/channel-socket.h"
|
||||||
@ -4389,7 +4388,7 @@ static CharDriverState *qmp_chardev_open_socket(const char *id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qapi_copy_SocketAddress(&s->addr, sock->addr);
|
s->addr = QAPI_CLONE(SocketAddress, sock->addr);
|
||||||
|
|
||||||
chr->opaque = s;
|
chr->opaque = s;
|
||||||
chr->chr_write = tcp_chr_write;
|
chr->chr_write = tcp_chr_write;
|
||||||
|
@ -1143,29 +1143,6 @@ SocketAddress *socket_remote_address(int fd, Error **errp)
|
|||||||
return socket_sockaddr_to_address(&ss, sslen, errp);
|
return socket_sockaddr_to_address(&ss, sslen, errp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void qapi_copy_SocketAddress(SocketAddress **p_dest,
|
|
||||||
SocketAddress *src)
|
|
||||||
{
|
|
||||||
Visitor *ov, *iv;
|
|
||||||
QObject *obj;
|
|
||||||
|
|
||||||
*p_dest = NULL;
|
|
||||||
|
|
||||||
ov = qmp_output_visitor_new(&obj);
|
|
||||||
visit_type_SocketAddress(ov, NULL, &src, &error_abort);
|
|
||||||
visit_complete(ov, &obj);
|
|
||||||
visit_free(ov);
|
|
||||||
if (!obj) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
iv = qmp_input_visitor_new(obj, true);
|
|
||||||
visit_type_SocketAddress(iv, NULL, p_dest, &error_abort);
|
|
||||||
visit_free(iv);
|
|
||||||
qobject_decref(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
|
char *socket_address_to_string(struct SocketAddress *addr, Error **errp)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
|
Loading…
Reference in New Issue
Block a user