Patchwork [RFC,RESEND,v1,05/15] virtproxy: add accept handler for communication channel

login
register
mail settings
Submitter Michael Roth
Date Nov. 3, 2010, 3:28 p.m.
Message ID <1288798090-7127-6-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/70020/
State New
Headers show

Comments

Michael Roth - Nov. 3, 2010, 3:28 p.m.
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 <mdroth@linux.vnet.ibm.com>
---
 virtproxy.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
Adam Litke - Nov. 3, 2010, 11:02 p.m.
On Wed, 2010-11-03 at 10:28 -0500, Michael Roth wrote:
> 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 <mdroth@linux.vnet.ibm.com>
> ---
>  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);
> +

Why the forward declaration?  Can you move the function to a different
place in the file to avoid this?


> +/* 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);
> +}
Michael Roth - Nov. 4, 2010, 4:17 p.m.
On 11/03/2010 06:02 PM, Adam Litke wrote:
> On Wed, 2010-11-03 at 10:28 -0500, Michael Roth wrote:
>> 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<mdroth@linux.vnet.ibm.com>
>> ---
>>   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);
>> +
>
> Why the forward declaration?  Can you move the function to a different
> place in the file to avoid this?
>
>

For this particular one vp_channel_accept and vp_channel_read reference 
each other at least this one needed a forward declaration. I'll see what 
I can do about these...I'm hesitant to add yet another header file but 
if that's preferred way I can move all the declarations into a 
virtproxy-internal.h file as you suggested.

Patch

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);
+}