diff mbox

[v2,1/4] net/socket: Convert the non-blocking connection mechanism to QIOchannel

Message ID 6824abf3c4e5b865de1799c302f60e8055c8d3dc.1493191677.git.maozy.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Mao Zhongyi April 26, 2017, 8:04 a.m. UTC
Currently, socket connection in net is realized by an old
mechanism which is non-blocking.

That old mechanism may cause net blocks on DNS lookups and
QEmu has already replaced it with QIOchannel in many features,
such as migration.

Convert it to QIOchannel for net as well.

CC: berrange@redhat.com, pbonzini@redhat.com, jasowang@redhat.com
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
---
The test steps like this:

    $ qemu-system-x86_64 -net nic -net socket,listen=:1234 ~/img/test.img
    $ qemu-system-x86_64 -net nic -net socket,connect=127.0.0.1:1234 ~/img/test.img

No exception.

 net/socket.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

Comments

Markus Armbruster April 27, 2017, 3:46 p.m. UTC | #1
Mao Zhongyi <maozy.fnst@cn.fujitsu.com> writes:

> Currently, socket connection in net is realized by an old
> mechanism which is non-blocking.
>
> That old mechanism may cause net blocks on DNS lookups and
> QEmu has already replaced it with QIOchannel in many features,
> such as migration.
>
> Convert it to QIOchannel for net as well.
>
> CC: berrange@redhat.com, pbonzini@redhat.com, jasowang@redhat.com
> Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
> ---
> The test steps like this:
>
>     $ qemu-system-x86_64 -net nic -net socket,listen=:1234 ~/img/test.img
>     $ qemu-system-x86_64 -net nic -net socket,connect=127.0.0.1:1234 ~/img/test.img
>
> No exception.
>
>  net/socket.c | 30 +++++++++++++++++++-----------
>  1 file changed, 19 insertions(+), 11 deletions(-)
>
> diff --git a/net/socket.c b/net/socket.c
> index b8c931e..52f9dce 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -33,6 +33,7 @@
>  #include "qemu/sockets.h"
>  #include "qemu/iov.h"
>  #include "qemu/main-loop.h"
> +#include "io/channel-socket.h"
>  
>  typedef struct NetSocketState {
>      NetClientState nc;
> @@ -525,16 +526,22 @@ typedef struct {
>      char *name;
>  } socket_connect_data;
>  
> -static void socket_connect_data_free(socket_connect_data *c)
> +static void socket_connect_data_free(void *opaque)
>  {
> +    socket_connect_data *c = opaque;

Blank line between declarations and statements, please.

> +    if (!c) {
> +        return;
> +    }
> +
>      qapi_free_SocketAddress(c->saddr);
>      g_free(c->model);
>      g_free(c->name);
>      g_free(c);
>  }
>  
> -static void net_socket_connected(int fd, Error *err, void *opaque)
> +static void net_socket_connected(QIOTask *task, void *opaque)
>  {
> +    QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
>      socket_connect_data *c = opaque;
>      NetSocketState *s;
>      char *addr_str = NULL;
> @@ -543,13 +550,13 @@ static void net_socket_connected(int fd, Error *err, void *opaque)
>      addr_str = socket_address_to_string(c->saddr, &local_error);
>      if (addr_str == NULL) {
>          error_report_err(local_error);
> -        closesocket(fd);
> +        closesocket(sioc->fd);
>          goto end;
>      }
>  
> -    s = net_socket_fd_init(c->peer, c->model, c->name, fd, true);
> +    s = net_socket_fd_init(c->peer, c->model, c->name, sioc->fd, true);
>      if (!s) {
> -        closesocket(fd);
> +        closesocket(sioc->fd);
>          goto end;
>      }
>  
> @@ -567,7 +574,7 @@ static int net_socket_connect_init(NetClientState *peer,
>                                     const char *host_str)
>  {
>      socket_connect_data *c = g_new0(socket_connect_data, 1);
> -    int fd = -1;
> +    QIOChannelSocket *sioc;
>      Error *local_error = NULL;
>  
>      c->peer = peer;
> @@ -578,11 +585,12 @@ static int net_socket_connect_init(NetClientState *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, net_socket_connected, c, &local_error);
> -    if (fd < 0) {
> -        goto err;
> -    }
> -
> +    sioc = qio_channel_socket_new();
> +    qio_channel_socket_connect_async(sioc,
> +                                     c->saddr,
> +                                     net_socket_connected,
> +                                     c,
> +                                     NULL);
>      return 0;
>  
>  err:
       error_report_err(local_error);
       socket_connect_data_free(c);
       return -1;
   }

Ignorant question: how does this change the reporting of errors?

Before the patch, errors from socket_connect() are reported with
error_report_err(), just like errors from socket_parse().

After the patch?

The next patch converts this function to Error.  Errors from
socket_parse() are then propagated to the caller.  What about errors
from socket_connect()?
Markus Armbruster April 27, 2017, 4:19 p.m. UTC | #2
Markus Armbruster <armbru@redhat.com> writes:

> Mao Zhongyi <maozy.fnst@cn.fujitsu.com> writes:
>
>> Currently, socket connection in net is realized by an old
>> mechanism which is non-blocking.
>>
>> That old mechanism may cause net blocks on DNS lookups and
>> QEmu has already replaced it with QIOchannel in many features,
>> such as migration.
>>
>> Convert it to QIOchannel for net as well.
>>
>> CC: berrange@redhat.com, pbonzini@redhat.com, jasowang@redhat.com
>> Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
>> ---
>> The test steps like this:
>>
>>     $ qemu-system-x86_64 -net nic -net socket,listen=:1234 ~/img/test.img
>>     $ qemu-system-x86_64 -net nic -net socket,connect=127.0.0.1:1234 ~/img/test.img
>>
>> No exception.
>>
>>  net/socket.c | 30 +++++++++++++++++++-----------
>>  1 file changed, 19 insertions(+), 11 deletions(-)
>>
>> diff --git a/net/socket.c b/net/socket.c
>> index b8c931e..52f9dce 100644
>> --- a/net/socket.c
>> +++ b/net/socket.c
>> @@ -33,6 +33,7 @@
>>  #include "qemu/sockets.h"
>>  #include "qemu/iov.h"
>>  #include "qemu/main-loop.h"
>> +#include "io/channel-socket.h"
>>  
>>  typedef struct NetSocketState {
>>      NetClientState nc;
>> @@ -525,16 +526,22 @@ typedef struct {
>>      char *name;
>>  } socket_connect_data;
>>  
>> -static void socket_connect_data_free(socket_connect_data *c)
>> +static void socket_connect_data_free(void *opaque)
>>  {
>> +    socket_connect_data *c = opaque;
>
> Blank line between declarations and statements, please.
>
>> +    if (!c) {
>> +        return;
>> +    }
>> +
>>      qapi_free_SocketAddress(c->saddr);
>>      g_free(c->model);
>>      g_free(c->name);
>>      g_free(c);
>>  }
>>  
>> -static void net_socket_connected(int fd, Error *err, void *opaque)
>> +static void net_socket_connected(QIOTask *task, void *opaque)
>>  {
>> +    QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
>>      socket_connect_data *c = opaque;
>>      NetSocketState *s;
>>      char *addr_str = NULL;
>> @@ -543,13 +550,13 @@ static void net_socket_connected(int fd, Error *err, void *opaque)
>>      addr_str = socket_address_to_string(c->saddr, &local_error);
>>      if (addr_str == NULL) {
>>          error_report_err(local_error);
>> -        closesocket(fd);
>> +        closesocket(sioc->fd);
>>          goto end;
>>      }
>>  
>> -    s = net_socket_fd_init(c->peer, c->model, c->name, fd, true);
>> +    s = net_socket_fd_init(c->peer, c->model, c->name, sioc->fd, true);
>>      if (!s) {
>> -        closesocket(fd);
>> +        closesocket(sioc->fd);

Actually, net_socket_fd_init() closes sioc->fd when it fails.  Closing
it again in the caller is wrong.  None of the other callers does it.
Please drop this line in a separate patch, before this one.

>>          goto end;
>>      }
>>  
[...]
Daniel P. Berrangé April 27, 2017, 4:20 p.m. UTC | #3
On Wed, Apr 26, 2017 at 04:04:15PM +0800, Mao Zhongyi wrote:
> Currently, socket connection in net is realized by an old
> mechanism which is non-blocking.
> 
> That old mechanism may cause net blocks on DNS lookups and
> QEmu has already replaced it with QIOchannel in many features,
> such as migration.
> 
> Convert it to QIOchannel for net as well.
> 
> CC: berrange@redhat.com, pbonzini@redhat.com, jasowang@redhat.com
> Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
> ---
> The test steps like this:
> 
>     $ qemu-system-x86_64 -net nic -net socket,listen=:1234 ~/img/test.img
>     $ qemu-system-x86_64 -net nic -net socket,connect=127.0.0.1:1234 ~/img/test.img
> 
> No exception.
> 
>  net/socket.c | 30 +++++++++++++++++++-----------
>  1 file changed, 19 insertions(+), 11 deletions(-)
> 
> diff --git a/net/socket.c b/net/socket.c
> index b8c931e..52f9dce 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -33,6 +33,7 @@
>  #include "qemu/sockets.h"
>  #include "qemu/iov.h"
>  #include "qemu/main-loop.h"
> +#include "io/channel-socket.h"
>  
>  typedef struct NetSocketState {
>      NetClientState nc;
> @@ -525,16 +526,22 @@ typedef struct {
>      char *name;
>  } socket_connect_data;
>  
> -static void socket_connect_data_free(socket_connect_data *c)
> +static void socket_connect_data_free(void *opaque)
>  {
> +    socket_connect_data *c = opaque;
> +    if (!c) {
> +        return;
> +    }
> +
>      qapi_free_SocketAddress(c->saddr);
>      g_free(c->model);
>      g_free(c->name);
>      g_free(c);
>  }
>  
> -static void net_socket_connected(int fd, Error *err, void *opaque)
> +static void net_socket_connected(QIOTask *task, void *opaque)
>  {
> +    QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
>      socket_connect_data *c = opaque;
>      NetSocketState *s;
>      char *addr_str = NULL;
> @@ -543,13 +550,13 @@ static void net_socket_connected(int fd, Error *err, void *opaque)
>      addr_str = socket_address_to_string(c->saddr, &local_error);
>      if (addr_str == NULL) {
>          error_report_err(local_error);
> -        closesocket(fd);
> +        closesocket(sioc->fd);
>          goto end;
>      }
>  
> -    s = net_socket_fd_init(c->peer, c->model, c->name, fd, true);
> +    s = net_socket_fd_init(c->peer, c->model, c->name, sioc->fd, true);
>      if (!s) {
> -        closesocket(fd);
> +        closesocket(sioc->fd);
>          goto end;
>      }
>  
> @@ -567,7 +574,7 @@ static int net_socket_connect_init(NetClientState *peer,
>                                     const char *host_str)
>  {
>      socket_connect_data *c = g_new0(socket_connect_data, 1);
> -    int fd = -1;
> +    QIOChannelSocket *sioc;
>      Error *local_error = NULL;
>  
>      c->peer = peer;
> @@ -578,11 +585,12 @@ static int net_socket_connect_init(NetClientState *peer,
>          goto err;
>      }
>  
> -    fd = socket_connect(c->saddr, net_socket_connected, c, &local_error);
> -    if (fd < 0) {
> -        goto err;
> -    }
> -
> +    sioc = qio_channel_socket_new();
> +    qio_channel_socket_connect_async(sioc,
> +                                     c->saddr,
> +                                     net_socket_connected,
> +                                     c,
> +                                     NULL);
>      return 0;

You've not saved a copy of the QIOChannelSocket poiinter here, and
the net_socket_connected() method doesn't release the reference
either. So htere is a memory leak. Of course if you relesae the
reference in net_socket_connected(), then you need to dup() the
file descriptor you're borrowing.

Regards,
Daniel
Daniel P. Berrangé April 27, 2017, 4:22 p.m. UTC | #4
On Thu, Apr 27, 2017 at 06:19:50PM +0200, Markus Armbruster wrote:
> Markus Armbruster <armbru@redhat.com> writes:
> 
> > Mao Zhongyi <maozy.fnst@cn.fujitsu.com> writes:
> >
> >> Currently, socket connection in net is realized by an old
> >> mechanism which is non-blocking.
> >>
> >> That old mechanism may cause net blocks on DNS lookups and
> >> QEmu has already replaced it with QIOchannel in many features,
> >> such as migration.
> >>
> >> Convert it to QIOchannel for net as well.
> >>
> >> CC: berrange@redhat.com, pbonzini@redhat.com, jasowang@redhat.com
> >> Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
> >> ---
> >> The test steps like this:
> >>
> >>     $ qemu-system-x86_64 -net nic -net socket,listen=:1234 ~/img/test.img
> >>     $ qemu-system-x86_64 -net nic -net socket,connect=127.0.0.1:1234 ~/img/test.img
> >>
> >> No exception.
> >>
> >>  net/socket.c | 30 +++++++++++++++++++-----------
> >>  1 file changed, 19 insertions(+), 11 deletions(-)
> >>
> >> diff --git a/net/socket.c b/net/socket.c
> >> index b8c931e..52f9dce 100644
> >> --- a/net/socket.c
> >> +++ b/net/socket.c
> >> @@ -33,6 +33,7 @@
> >>  #include "qemu/sockets.h"
> >>  #include "qemu/iov.h"
> >>  #include "qemu/main-loop.h"
> >> +#include "io/channel-socket.h"
> >>  
> >>  typedef struct NetSocketState {
> >>      NetClientState nc;
> >> @@ -525,16 +526,22 @@ typedef struct {
> >>      char *name;
> >>  } socket_connect_data;
> >>  
> >> -static void socket_connect_data_free(socket_connect_data *c)
> >> +static void socket_connect_data_free(void *opaque)
> >>  {
> >> +    socket_connect_data *c = opaque;
> >
> > Blank line between declarations and statements, please.
> >
> >> +    if (!c) {
> >> +        return;
> >> +    }
> >> +
> >>      qapi_free_SocketAddress(c->saddr);
> >>      g_free(c->model);
> >>      g_free(c->name);
> >>      g_free(c);
> >>  }
> >>  
> >> -static void net_socket_connected(int fd, Error *err, void *opaque)
> >> +static void net_socket_connected(QIOTask *task, void *opaque)
> >>  {
> >> +    QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
> >>      socket_connect_data *c = opaque;
> >>      NetSocketState *s;
> >>      char *addr_str = NULL;
> >> @@ -543,13 +550,13 @@ static void net_socket_connected(int fd, Error *err, void *opaque)
> >>      addr_str = socket_address_to_string(c->saddr, &local_error);
> >>      if (addr_str == NULL) {
> >>          error_report_err(local_error);
> >> -        closesocket(fd);
> >> +        closesocket(sioc->fd);
> >>          goto end;
> >>      }
> >>  
> >> -    s = net_socket_fd_init(c->peer, c->model, c->name, fd, true);
> >> +    s = net_socket_fd_init(c->peer, c->model, c->name, sioc->fd, true);
> >>      if (!s) {
> >> -        closesocket(fd);
> >> +        closesocket(sioc->fd);
> 
> Actually, net_socket_fd_init() closes sioc->fd when it fails.  Closing
> it again in the caller is wrong.  None of the other callers does it.
> Please drop this line in a separate patch, before this one.

NB, technically the 'fd' is still owned by the 'sioc' object, so nothing
should close it. If we weren't already leaking the 'sioc' object we would
have a double close here....

Regards,
Daniel
Mao Zhongyi May 3, 2017, 7:02 a.m. UTC | #5
Hi Markus,

Thanks for your reply.

On 04/27/2017 11:46 PM, Markus Armbruster wrote:
> Mao Zhongyi <maozy.fnst@cn.fujitsu.com> writes:
>
>> Currently, socket connection in net is realized by an old
>> mechanism which is non-blocking.
>>
>> That old mechanism may cause net blocks on DNS lookups and
>> QEmu has already replaced it with QIOchannel in many features,
>> such as migration.
>>
>> Convert it to QIOchannel for net as well.
>>
>> CC: berrange@redhat.com, pbonzini@redhat.com, jasowang@redhat.com
>> Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
>> ---
>> The test steps like this:
>>
>>     $ qemu-system-x86_64 -net nic -net socket,listen=:1234 ~/img/test.img
>>     $ qemu-system-x86_64 -net nic -net socket,connect=127.0.0.1:1234 ~/img/test.img
>>
>> No exception.
>>
>>  net/socket.c | 30 +++++++++++++++++++-----------
>>  1 file changed, 19 insertions(+), 11 deletions(-)
>>
>> diff --git a/net/socket.c b/net/socket.c
>> index b8c931e..52f9dce 100644
>> --- a/net/socket.c
>> +++ b/net/socket.c
>> @@ -33,6 +33,7 @@
>>  #include "qemu/sockets.h"
>>  #include "qemu/iov.h"
>>  #include "qemu/main-loop.h"
>> +#include "io/channel-socket.h"
>>
>>  typedef struct NetSocketState {
>>      NetClientState nc;
>> @@ -525,16 +526,22 @@ typedef struct {
>>      char *name;
>>  } socket_connect_data;
>>
>> -static void socket_connect_data_free(socket_connect_data *c)
>> +static void socket_connect_data_free(void *opaque)
>>  {
>> +    socket_connect_data *c = opaque;
>
> Blank line between declarations and statements, please.

OK, I see.

>
>> +    if (!c) {
>> +        return;
>> +    }
>> +
>>      qapi_free_SocketAddress(c->saddr);
>>      g_free(c->model);
>>      g_free(c->name);
>>      g_free(c);
>>  }
>>
>> -static void net_socket_connected(int fd, Error *err, void *opaque)
>> +static void net_socket_connected(QIOTask *task, void *opaque)
>>  {
>> +    QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
>>      socket_connect_data *c = opaque;
>>      NetSocketState *s;
>>      char *addr_str = NULL;
>> @@ -543,13 +550,13 @@ static void net_socket_connected(int fd, Error *err, void *opaque)
>>      addr_str = socket_address_to_string(c->saddr, &local_error);
>>      if (addr_str == NULL) {
>>          error_report_err(local_error);
>> -        closesocket(fd);
>> +        closesocket(sioc->fd);
>>          goto end;
>>      }
>>
>> -    s = net_socket_fd_init(c->peer, c->model, c->name, fd, true);
>> +    s = net_socket_fd_init(c->peer, c->model, c->name, sioc->fd, true);
>>      if (!s) {
>> -        closesocket(fd);
>> +        closesocket(sioc->fd);
>>          goto end;
>>      }
>>
>> @@ -567,7 +574,7 @@ static int net_socket_connect_init(NetClientState *peer,
>>                                     const char *host_str)
>>  {
>>      socket_connect_data *c = g_new0(socket_connect_data, 1);
>> -    int fd = -1;
>> +    QIOChannelSocket *sioc;
>>      Error *local_error = NULL;
>>
>>      c->peer = peer;
>> @@ -578,11 +585,12 @@ static int net_socket_connect_init(NetClientState *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, net_socket_connected, c, &local_error);
>> -    if (fd < 0) {
>> -        goto err;
>> -    }
>> -
>> +    sioc = qio_channel_socket_new();
>> +    qio_channel_socket_connect_async(sioc,
>> +                                     c->saddr,
>> +                                     net_socket_connected,
>> +                                     c,
>> +                                     NULL);
>>      return 0;
>>
>>  err:
>        error_report_err(local_error);
>        socket_connect_data_free(c);
>        return -1;
>    }
>
> Ignorant question: how does this change the reporting of errors?
>
> Before the patch, errors from socket_connect() are reported with
> error_report_err(), just like errors from socket_parse().
>
> After the patch?
>
> The next patch converts this function to Error.  Errors from
> socket_parse() are then propagated to the caller.  What about errors
> from socket_connect()?

I'm really careless. I intend to report errors from socket_connect()
in the net_socket_connected(), but it doesn't continue to propagate to
the caller as socket_parse(). Because if not, plenty of QIOChannel
codes should be modified. It seems not a proper way. So I will report
it in the net_socket_connected() whit v3.

Thanks
Mao
>
>
>
>
>
Mao Zhongyi May 3, 2017, 7:02 a.m. UTC | #6
Hi, Daniel

On 04/28/2017 12:20 AM, Daniel P. Berrange wrote:
> On Wed, Apr 26, 2017 at 04:04:15PM +0800, Mao Zhongyi wrote:
>> Currently, socket connection in net is realized by an old
>> mechanism which is non-blocking.

[...]

             NULL);
>>      return 0;
>
> You've not saved a copy of the QIOChannelSocket poiinter here, and
> the net_socket_connected() method doesn't release the reference
> either. So htere is a memory leak. Of course if you relesae the
> reference in net_socket_connected(), then you need to dup() the
> file descriptor you're borrowing.
>
> Regards,
> Daniel


Sorry for delay, thanks for your detailed reply.
I see, will fix it in the next version.

Thanks
Mao
>
diff mbox

Patch

diff --git a/net/socket.c b/net/socket.c
index b8c931e..52f9dce 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -33,6 +33,7 @@ 
 #include "qemu/sockets.h"
 #include "qemu/iov.h"
 #include "qemu/main-loop.h"
+#include "io/channel-socket.h"
 
 typedef struct NetSocketState {
     NetClientState nc;
@@ -525,16 +526,22 @@  typedef struct {
     char *name;
 } socket_connect_data;
 
-static void socket_connect_data_free(socket_connect_data *c)
+static void socket_connect_data_free(void *opaque)
 {
+    socket_connect_data *c = opaque;
+    if (!c) {
+        return;
+    }
+
     qapi_free_SocketAddress(c->saddr);
     g_free(c->model);
     g_free(c->name);
     g_free(c);
 }
 
-static void net_socket_connected(int fd, Error *err, void *opaque)
+static void net_socket_connected(QIOTask *task, void *opaque)
 {
+    QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(qio_task_get_source(task));
     socket_connect_data *c = opaque;
     NetSocketState *s;
     char *addr_str = NULL;
@@ -543,13 +550,13 @@  static void net_socket_connected(int fd, Error *err, void *opaque)
     addr_str = socket_address_to_string(c->saddr, &local_error);
     if (addr_str == NULL) {
         error_report_err(local_error);
-        closesocket(fd);
+        closesocket(sioc->fd);
         goto end;
     }
 
-    s = net_socket_fd_init(c->peer, c->model, c->name, fd, true);
+    s = net_socket_fd_init(c->peer, c->model, c->name, sioc->fd, true);
     if (!s) {
-        closesocket(fd);
+        closesocket(sioc->fd);
         goto end;
     }
 
@@ -567,7 +574,7 @@  static int net_socket_connect_init(NetClientState *peer,
                                    const char *host_str)
 {
     socket_connect_data *c = g_new0(socket_connect_data, 1);
-    int fd = -1;
+    QIOChannelSocket *sioc;
     Error *local_error = NULL;
 
     c->peer = peer;
@@ -578,11 +585,12 @@  static int net_socket_connect_init(NetClientState *peer,
         goto err;
     }
 
-    fd = socket_connect(c->saddr, net_socket_connected, c, &local_error);
-    if (fd < 0) {
-        goto err;
-    }
-
+    sioc = qio_channel_socket_new();
+    qio_channel_socket_connect_async(sioc,
+                                     c->saddr,
+                                     net_socket_connected,
+                                     c,
+                                     NULL);
     return 0;
 
 err: