From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44450) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bc93E-0002xd-Mn for qemu-devel@nongnu.org; Tue, 23 Aug 2016 06:35:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bc93B-0001V1-2q for qemu-devel@nongnu.org; Tue, 23 Aug 2016 06:35:24 -0400 Received: from [59.151.112.132] (port=30339 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bc93A-0001Rw-M6 for qemu-devel@nongnu.org; Tue, 23 Aug 2016 06:35:21 -0400 References: <20160823094537.8782-1-marcandre.lureau@redhat.com> <20160823094537.8782-3-marcandre.lureau@redhat.com> From: Cao jin Message-ID: <57BC28EA.8070700@cn.fujitsu.com> Date: Tue, 23 Aug 2016 18:43:54 +0800 MIME-Version: 1.0 In-Reply-To: <20160823094537.8782-3-marcandre.lureau@redhat.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH for-2.7 2/2] net: make socket connect non-blocking again List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?UTF-8?Q?Marc-Andr=c3=a9_Lureau?= , qemu-devel@nongnu.org Cc: jasowang@redhat.com, crobinso@redhat.com, ashijeetacharya@gmail.com, pbonzini@redhat.com, "Daniel P. Berrange" Hi, I just noticed you still using the old-style non-blocking connect(which will still block when query DNS), which will be removed (suggested by Daniel), but the patch is still on the way. So I guess maybe you should switch to QIOChannel way. FYI: http://lists.nongnu.org/archive/html/qemu-devel/2016-07/msg06386.html http://lists.nongnu.org/archive/html/qemu-devel/2016-08/msg00046.html Cao jin On 08/23/2016 05:45 PM, Marc-André Lureau wrote: > 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 > --- > 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, >