Initial commit with version 1.2.0-24
[packages/centos6/qemu.git] / 0402-iohandlers-Add-enable-disable_write_fd_handler-funct.patch
1 From 2ac23d2134611b4e5b0fb389911bd03baa685df3 Mon Sep 17 00:00:00 2001
2 From: Amit Shah <amit.shah@redhat.com>
3 Date: Mon, 21 Mar 2011 20:32:58 +0100
4 Subject: [PATCH] iohandlers: Add enable/disable_write_fd_handler() functions
5
6 These will be used to provide a cleaner API for the nonblocking case.
7
8 Signed-off-by: Amit Shah <amit.shah@redhat.com>
9 Signed-off-by: Cole Robinson <crobinso@redhat.com>
10 ---
11  iohandler.c | 35 +++++++++++++++++++++++++++++++++++
12  main-loop.h |  3 +++
13  2 files changed, 38 insertions(+)
14
15 diff --git a/iohandler.c b/iohandler.c
16 index a2d871b..c00fecd 100644
17 --- a/iohandler.c
18 +++ b/iohandler.c
19 @@ -45,6 +45,41 @@ typedef struct IOHandlerRecord {
20  static QLIST_HEAD(, IOHandlerRecord) io_handlers =
21      QLIST_HEAD_INITIALIZER(io_handlers);
22  
23 +static IOHandlerRecord *find_iohandler(int fd)
24 +{
25 +    IOHandlerRecord *ioh;
26 +
27 +    QLIST_FOREACH(ioh, &io_handlers, next) {
28 +        if (ioh->fd == fd) {
29 +            return ioh;
30 +        }
31 +    }
32 +    return NULL;
33 +}
34 +
35 +void enable_write_fd_handler(int fd, IOHandler *fd_write)
36 +{
37 +    IOHandlerRecord *ioh;
38 +
39 +    ioh = find_iohandler(fd);
40 +    if (!ioh) {
41 +        return;
42 +    }
43 +
44 +    ioh->fd_write = fd_write;
45 +}
46 +
47 +void disable_write_fd_handler(int fd)
48 +{
49 +    IOHandlerRecord *ioh;
50 +
51 +    ioh = find_iohandler(fd);
52 +    if (!ioh) {
53 +        return;
54 +    }
55 +
56 +    ioh->fd_write = NULL;
57 +}
58  
59  /* XXX: fd_read_poll should be suppressed, but an API change is
60     necessary in the character devices to suppress fd_can_read(). */
61 diff --git a/main-loop.h b/main-loop.h
62 index dce1cd9..eb31273 100644
63 --- a/main-loop.h
64 +++ b/main-loop.h
65 @@ -175,6 +175,9 @@ typedef void IOReadHandler(void *opaque, const uint8_t *buf, int size);
66  typedef int IOCanReadHandler(void *opaque);
67  typedef void IOHandler(void *opaque);
68  
69 +void enable_write_fd_handler(int fd, IOHandler *fd_write);
70 +void disable_write_fd_handler(int fd);
71 +
72  /**
73   * qemu_set_fd_handler2: Register a file descriptor with the main loop
74   *
75 -- 
76 1.7.12.1
77