From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51663 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDfGf-0001Lt-Pd for qemu-devel@nongnu.org; Wed, 03 Nov 2010 11:28:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDfGe-00073z-9N for qemu-devel@nongnu.org; Wed, 03 Nov 2010 11:28:53 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:52520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDfGe-00073h-6x for qemu-devel@nongnu.org; Wed, 03 Nov 2010 11:28:52 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id oA3FTaC4000610 for ; Wed, 3 Nov 2010 11:29:36 -0400 Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oA3FSmIe152128 for ; Wed, 3 Nov 2010 11:28:48 -0400 Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by d01av01.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oA3FSlZU007714 for ; Wed, 3 Nov 2010 11:28:48 -0400 From: Michael Roth Date: Wed, 3 Nov 2010 10:28:00 -0500 Message-Id: <1288798090-7127-6-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1288798090-7127-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1288798090-7127-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [RFC][RESEND][PATCH v1 05/15] virtproxy: add accept handler for communication channel List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: abeekhof@redhat.com, agl@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, aliguori@linux.vnet.ibm.com This accept()'s connections to the socket we told virt-proxy to listen for the channel connection on and sets the appropriate read handler for the resulting FD. Signed-off-by: Michael Roth --- virtproxy.c | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/virtproxy.c b/virtproxy.c index fa17722..20532c2 100644 --- a/virtproxy.c +++ b/virtproxy.c @@ -166,6 +166,8 @@ static VPConn *get_conn(const VPDriver *drv, int fd, bool client) return NULL; } +static void vp_channel_accept(void *opaque); + /* get VPOForward by service_id */ static VPOForward *get_oforward(const VPDriver *drv, const char *service_id) { @@ -193,3 +195,38 @@ static VPIForward *get_iforward(const VPDriver *drv, const char *service_id) return NULL; } + +/* accept handler for communication channel + * + * accept()s connection to communication channel (for sockets), and sets + * up the read handler for resulting FD. + */ +static void vp_channel_accept(void *opaque) +{ + VPDriver *drv = opaque; + struct sockaddr_in saddr; + struct sockaddr *addr; + socklen_t len; + int fd; + + TRACE("called with opaque: %p", drv); + + for(;;) { + len = sizeof(saddr); + addr = (struct sockaddr *)&saddr; + fd = qemu_accept(drv->listen_fd, addr, &len); + + if (fd < 0 && errno != EINTR) { + TRACE("accept() failed"); + return; + } else if (fd >= 0) { + TRACE("accepted connection"); + break; + } + } + + drv->channel_fd = fd; + vp_set_fd_handler(drv->channel_fd, vp_channel_read, NULL, drv); + /* dont accept anymore connections until channel_fd is closed */ + vp_set_fd_handler(drv->listen_fd, NULL, NULL, NULL); +} -- 1.7.0.4