@@ -1084,7 +1084,11 @@ int set_read_poll_fd_action(int fd, bool enable)
if (!ioh) {
return -1;
}
- ioh->read_poll_enabled = enable;
+
+ ioh->read_poll_enabled = false;
+ if (enable && ioh->fd_read_poll) {
+ ioh->read_poll_enabled = true;
+ }
return 0;
}
@@ -1098,7 +1102,11 @@ int set_read_fd_action(int fd, bool enable)
if (!ioh) {
return -1;
}
- ioh->read_enabled = enable;
+
+ ioh->read_enabled = false;
+ if (enable && ioh->fd_read) {
+ ioh->read_enabled = true;
+ }
return 0;
}
@@ -1112,7 +1120,11 @@ int set_write_fd_action(int fd, bool enable)
if (!ioh) {
return -1;
}
- ioh->write_enabled = enable;
+
+ ioh->write_enabled = false;
+ if (enable && ioh->fd_write) {
+ ioh->write_enabled = true;
+ }
return 0;
}
@@ -1391,14 +1403,13 @@ void main_loop_wait(int nonblocking)
QLIST_FOREACH(ioh, &io_handlers, next) {
if (ioh->deleted)
continue;
- if (ioh->fd_read && ioh->read_enabled &&
- (!ioh->fd_read_poll ||
- (!ioh->read_poll_enabled || ioh->fd_read_poll(ioh->opaque) != 0))) {
+ if (ioh->read_enabled &&
+ (!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 && ioh->write_enabled) {
+ if (ioh->write_enabled) {
FD_SET(ioh->fd, &wfds);
if (ioh->fd > nfds)
nfds = ioh->fd;
@@ -1417,10 +1428,10 @@ void main_loop_wait(int nonblocking)
IOHandlerRecord *pioh;
QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) {
- if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
+ if (!ioh->deleted && ioh->read_enabled && FD_ISSET(ioh->fd, &rfds)) {
ioh->fd_read(ioh->opaque);
}
- if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
+ if (!ioh->deleted && ioh->write_enabled && FD_ISSET(ioh->fd, &wfds)) {
ioh->fd_write(ioh->opaque);
}
If an iohandler is asked to be enabled but the handler doesn't exist, don't enable the handler. This can be used to simplify the conditions in main_loop_wait(). Signed-off-by: Amit Shah <amit.shah@redhat.com> --- vl.c | 29 ++++++++++++++++++++--------- 1 files changed, 20 insertions(+), 9 deletions(-)