[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/5] iohandlers: Allow each iohandler to be enabled/
From: |
Amit Shah |
Subject: |
[Qemu-devel] [PATCH 3/5] iohandlers: Allow each iohandler to be enabled/disabled individually |
Date: |
Thu, 13 Jan 2011 18:30:08 +0530 |
Each iohandler for an fd can now be individually enabled or disabled.
Signed-off-by: Amit Shah <address@hidden>
---
qemu-char.h | 4 ++++
vl.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 58 insertions(+), 4 deletions(-)
diff --git a/qemu-char.h b/qemu-char.h
index 0ef83f4..e88a108 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -115,6 +115,10 @@ int assign_fd_handlers(int fd,
IOHandler *fd_write,
void *opaque);
void remove_fd_handlers(int fd);
+int set_read_poll_fd_action(int fd, bool enable);
+int set_read_fd_action(int fd, bool enable);
+int set_write_fd_action(int fd, bool enable);
+
int qemu_set_fd_handler2(int fd,
IOCanReadHandler *fd_read_poll,
IOHandler *fd_read,
diff --git a/vl.c b/vl.c
index 38e0a3c..a0b14b5 100644
--- a/vl.c
+++ b/vl.c
@@ -1014,6 +1014,9 @@ typedef struct IOHandlerRecord {
IOHandler *fd_write;
int deleted;
void *opaque;
+ bool read_poll_enabled;
+ bool read_enabled;
+ bool write_enabled;
/* temporary data */
struct pollfd *ufd;
QLIST_ENTRY(IOHandlerRecord) next;
@@ -1062,6 +1065,7 @@ int assign_fd_handlers(int fd,
ioh->fd_write = fd_write;
ioh->opaque = opaque;
ioh->deleted = 0;
+ ioh->read_poll_enabled = ioh->read_enabled = ioh->write_enabled = false;
return 0;
}
@@ -1071,13 +1075,59 @@ void remove_fd_handlers(int fd)
assign_fd_handlers(fd, NULL, NULL, NULL, NULL);
}
+int set_read_poll_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->read_poll_enabled = enable;
+
+ return 0;
+}
+
+int set_read_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->read_enabled = enable;
+
+ return 0;
+}
+
+int set_write_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->write_enabled = enable;
+
+ return 0;
+}
+
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);
+ assign_fd_handlers(fd, fd_read_poll, fd_read, fd_write, opaque);
+ set_read_poll_fd_action(fd, true);
+ set_read_fd_action(fd, true);
+ set_write_fd_action(fd, true);
+ return 0;
}
int qemu_set_fd_handler(int fd,
@@ -1341,14 +1391,14 @@ void main_loop_wait(int nonblocking)
QLIST_FOREACH(ioh, &io_handlers, next) {
if (ioh->deleted)
continue;
- if (ioh->fd_read &&
+ if (ioh->fd_read && ioh->read_enabled &&
(!ioh->fd_read_poll ||
- ioh->fd_read_poll(ioh->opaque) != 0)) {
+ (!ioh->read_poll_enabled || ioh->fd_read_poll(ioh->opaque) !=
0))) {
FD_SET(ioh->fd, &rfds);
if (ioh->fd > nfds)
nfds = ioh->fd;
}
- if (ioh->fd_write) {
+ if (ioh->fd_write && ioh->write_enabled) {
FD_SET(ioh->fd, &wfds);
if (ioh->fd > nfds)
nfds = ioh->fd;
--
1.7.3.4
[Qemu-devel] [PATCH 4/5] iohandlers: Enable an iohandler only if the associated handler exists, Amit Shah, 2011/01/13
[Qemu-devel] [PATCH 5/5] iohandlers: Add IOHandlerOps struct, Amit Shah, 2011/01/13
[Qemu-devel] Re: [PATCH 0/5] iohandlers: Add support for enabling/disabling individual handlers, Gerd Hoffmann, 2011/01/13