Patchwork [2/5] iohandlers: Introduce assign_fd_handlers() and remove_fd_handlers

login
register
mail settings
Submitter Amit Shah
Date Jan. 13, 2011, 1 p.m.
Message ID <62faeb8db4ea4f9dc0dd7778e9643d13947714ff.1294923288.git.amit.shah@redhat.com>
Download mbox | patch
Permalink /patch/78750/
State New
Headers show

Comments

Amit Shah - Jan. 13, 2011, 1 p.m.
This function will be used to assign fd handlers.  Future commits will
be enable each handler to be enabled/disabled individually.

Make qemu_set_fd_handler2() a wrapper to assign_fd_handlers().

remove_fd_handlers() removes all the assigned handlers and marks the
iohandler for deletion.  It's a wrapper to assign_fd_handlers() with
NULL handlers.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
 qemu-char.h |    6 ++++++
 vl.c        |   24 +++++++++++++++++++-----
 2 files changed, 25 insertions(+), 5 deletions(-)
Gerd Hoffmann - Jan. 13, 2011, 1:59 p.m.
On 01/13/11 14:00, Amit Shah wrote:
> This function will be used to assign fd handlers.  Future commits will
> be enable each handler to be enabled/disabled individually.
>
> Make qemu_set_fd_handler2() a wrapper to assign_fd_handlers().
>
> remove_fd_handlers() removes all the assigned handlers and marks the
> iohandler for deletion.  It's a wrapper to assign_fd_handlers() with
> NULL handlers.
>
> Signed-off-by: Amit Shah<amit.shah@redhat.com>
> ---
>   qemu-char.h |    6 ++++++
>   vl.c        |   24 +++++++++++++++++++-----
>   2 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/qemu-char.h b/qemu-char.h
> index e6ee6c4..0ef83f4 100644
> --- a/qemu-char.h
> +++ b/qemu-char.h
> @@ -109,6 +109,12 @@ size_t qemu_chr_mem_osize(const CharDriverState *chr);
>
>   /* async I/O support */
>
> +int assign_fd_handlers(int fd,
> +                       IOCanReadHandler *fd_read_poll,
> +                       IOHandler *fd_read,
> +                       IOHandler *fd_write,
> +                       void *opaque);
> +void remove_fd_handlers(int fd);

A comment documenting the new functions would be nice.

cheers,
   Gerd
Amit Shah - Jan. 13, 2011, 2:10 p.m.
On (Thu) Jan 13 2011 [14:59:26], Gerd Hoffmann wrote:
> >+int assign_fd_handlers(int fd,
> >+                       IOCanReadHandler *fd_read_poll,
> >+                       IOHandler *fd_read,
> >+                       IOHandler *fd_write,
> >+                       void *opaque);
> >+void remove_fd_handlers(int fd);
> 
> A comment documenting the new functions would be nice.

Good idea; I'll do that.

		Amit

Patch

diff --git a/qemu-char.h b/qemu-char.h
index e6ee6c4..0ef83f4 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -109,6 +109,12 @@  size_t qemu_chr_mem_osize(const CharDriverState *chr);
 
 /* async I/O support */
 
+int assign_fd_handlers(int fd,
+                       IOCanReadHandler *fd_read_poll,
+                       IOHandler *fd_read,
+                       IOHandler *fd_write,
+                       void *opaque);
+void remove_fd_handlers(int fd);
 int qemu_set_fd_handler2(int fd,
                          IOCanReadHandler *fd_read_poll,
                          IOHandler *fd_read,
diff --git a/vl.c b/vl.c
index 9e365f6..38e0a3c 100644
--- a/vl.c
+++ b/vl.c
@@ -1036,11 +1036,11 @@  static IOHandlerRecord *get_iohandler(int fd)
 
 /* XXX: fd_read_poll should be suppressed, but an API change is
    necessary in the character devices to suppress fd_can_read(). */
-int qemu_set_fd_handler2(int fd,
-                         IOCanReadHandler *fd_read_poll,
-                         IOHandler *fd_read,
-                         IOHandler *fd_write,
-                         void *opaque)
+int assign_fd_handlers(int fd,
+                       IOCanReadHandler *fd_read_poll,
+                       IOHandler *fd_read,
+                       IOHandler *fd_write,
+                       void *opaque)
 {
     IOHandlerRecord *ioh;
 
@@ -1066,6 +1066,20 @@  int qemu_set_fd_handler2(int fd,
     return 0;
 }
 
+void remove_fd_handlers(int fd)
+{
+    assign_fd_handlers(fd, NULL, NULL, NULL, NULL);
+}
+
+int qemu_set_fd_handler2(int fd,
+                         IOCanReadHandler *fd_read_poll,
+                         IOHandler *fd_read,
+                         IOHandler *fd_write,
+                         void *opaque)
+{
+    return assign_fd_handlers(fd, fd_read_poll, fd_read, fd_write, opaque);
+}
+
 int qemu_set_fd_handler(int fd,
                         IOHandler *fd_read,
                         IOHandler *fd_write,