From 7a17b608de24e3aaf7d5ca030bb80a74dcc3baf9 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Wed, 17 Nov 2010 17:58:29 +0100 Subject: Implementation of event loop abstraction. This patch adds "android/looper.h" which provides an abstraction for event loops: - android/looper-qemu.c implements it on top of the QEMU main event loop. - android/looper-generic.c implements it on top of an IoLooper object. The main idea is to move the UI-related code to use the abstraction to handle timers and asynchronous (network) i/o. NOTE: Code compiles but has not been heavily tested. Change-Id: Ib6820c1b9a9950dc22449a332bc1b066a07af203 --- iolooper-select.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'iolooper-select.c') diff --git a/iolooper-select.c b/iolooper-select.c index dbb18dd..dc5257c 100644 --- a/iolooper-select.c +++ b/iolooper-select.c @@ -57,6 +57,29 @@ iolooper_del_fd( IoLooper* iol, int fd ) iol->max_fd_valid = 0; } +void +iolooper_modify( IoLooper* iol, int fd, int oldflags, int newflags ) +{ + if (fd < 0) + return; + + int changed = oldflags ^ newflags; + + if ((changed & IOLOOPER_READ) != 0) { + if ((newflags & IOLOOPER_READ) != 0) + FD_SET(fd, iol->reads); + else + FD_CLR(fd, iol->reads); + } + if ((changed & IOLOOPER_WRITE) != 0) { + if ((newflags & IOLOOPER_WRITE) != 0) + FD_SET(fd, iol->writes); + else + FD_CLR(fd, iol->writes); + } +} + + static int iolooper_fd_count( IoLooper* iol ) { -- cgit v1.1