Revision a3e4b4a8 iohandler.c
b/iohandler.c | ||
---|---|---|
39 | 39 |
void *opaque; |
40 | 40 |
QLIST_ENTRY(IOHandlerRecord) next; |
41 | 41 |
int fd; |
42 |
int pollfds_idx; |
|
42 | 43 |
bool deleted; |
43 | 44 |
} IOHandlerRecord; |
44 | 45 |
|
... | ... | |
78 | 79 |
ioh->fd_read = fd_read; |
79 | 80 |
ioh->fd_write = fd_write; |
80 | 81 |
ioh->opaque = opaque; |
82 |
ioh->pollfds_idx = -1; |
|
81 | 83 |
ioh->deleted = 0; |
82 | 84 |
qemu_notify_event(); |
83 | 85 |
} |
... | ... | |
92 | 94 |
return qemu_set_fd_handler2(fd, NULL, fd_read, fd_write, opaque); |
93 | 95 |
} |
94 | 96 |
|
95 |
void qemu_iohandler_fill(int *pnfds, fd_set *readfds, fd_set *writefds, fd_set *xfds)
|
|
97 |
void qemu_iohandler_fill(GArray *pollfds)
|
|
96 | 98 |
{ |
97 | 99 |
IOHandlerRecord *ioh; |
98 | 100 |
|
99 | 101 |
QLIST_FOREACH(ioh, &io_handlers, next) { |
102 |
int events = 0; |
|
103 |
|
|
100 | 104 |
if (ioh->deleted) |
101 | 105 |
continue; |
102 | 106 |
if (ioh->fd_read && |
103 | 107 |
(!ioh->fd_read_poll || |
104 | 108 |
ioh->fd_read_poll(ioh->opaque) != 0)) { |
105 |
FD_SET(ioh->fd, readfds); |
|
106 |
if (ioh->fd > *pnfds) |
|
107 |
*pnfds = ioh->fd; |
|
109 |
events |= G_IO_IN | G_IO_HUP | G_IO_ERR; |
|
108 | 110 |
} |
109 | 111 |
if (ioh->fd_write) { |
110 |
FD_SET(ioh->fd, writefds); |
|
111 |
if (ioh->fd > *pnfds) |
|
112 |
*pnfds = ioh->fd; |
|
112 |
events |= G_IO_OUT | G_IO_ERR; |
|
113 |
} |
|
114 |
if (events) { |
|
115 |
GPollFD pfd = { |
|
116 |
.fd = ioh->fd, |
|
117 |
.events = events, |
|
118 |
}; |
|
119 |
ioh->pollfds_idx = pollfds->len; |
|
120 |
g_array_append_val(pollfds, pfd); |
|
121 |
} else { |
|
122 |
ioh->pollfds_idx = -1; |
|
113 | 123 |
} |
114 | 124 |
} |
115 | 125 |
} |
116 | 126 |
|
117 |
void qemu_iohandler_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds, int ret)
|
|
127 |
void qemu_iohandler_poll(GArray *pollfds, int ret)
|
|
118 | 128 |
{ |
119 | 129 |
if (ret > 0) { |
120 | 130 |
IOHandlerRecord *pioh, *ioh; |
121 | 131 |
|
122 | 132 |
QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) { |
123 |
if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, readfds)) { |
|
133 |
int revents = 0; |
|
134 |
|
|
135 |
if (!ioh->deleted && ioh->pollfds_idx != -1) { |
|
136 |
GPollFD *pfd = &g_array_index(pollfds, GPollFD, |
|
137 |
ioh->pollfds_idx); |
|
138 |
revents = pfd->revents; |
|
139 |
} |
|
140 |
|
|
141 |
if (!ioh->deleted && ioh->fd_read && |
|
142 |
(revents & (G_IO_IN | G_IO_HUP | G_IO_ERR))) { |
|
124 | 143 |
ioh->fd_read(ioh->opaque); |
125 | 144 |
} |
126 |
if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, writefds)) { |
|
145 |
if (!ioh->deleted && ioh->fd_write && |
|
146 |
(revents & (G_IO_OUT | G_IO_ERR))) { |
|
127 | 147 |
ioh->fd_write(ioh->opaque); |
128 | 148 |
} |
129 | 149 |
|
Also available in: Unified diff