Since commit 7e8449594c929, the socket connect code is blocking, because
calling socket_connect() without callback is blocking. Make it
non-blocking by adding a callback. Unfortunately, the callback needs
many local variables that are not easy to get rid of (it can't easily
create the qemu_new_net_client() earlier). By adding the callback, the
socket is also made non-blocking. If the socket attempt succeeded
immediately, the callback is still being called.
Signed-off-by: Marc-André Lureau <address@hidden>
---
net/socket.c | 82 +++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 53 insertions(+), 29 deletions(-)
+
+static int net_socket_connect_init(NetClientState *peer,
+ const char *model,
+ const char *name,
+ const char *host_str)
+{
+ socket_connect_data *c = g_new0(socket_connect_data, 1);
+ int fd = -1;
+ Error *local_error = NULL;
+
+ c->peer = peer;
+ c->model = g_strdup(model);
+ c->name = g_strdup(name);
+ c->saddr = socket_parse(host_str, &local_error);
+ if (c->saddr == NULL) {
+ goto err;
+ }
+
+ fd = socket_connect(c->saddr, &local_error, net_socket_connected, c);
+ if (fd < 0) {
+ goto err;
+ }
+
+ return 0;
+
+err:
+ error_report_err(local_error);
+ socket_connect_data_free(c);
+ return -1;
}
static int net_socket_mcast_init(NetClientState *peer,