diff options
author | Vladimir Chtchetkine <vchtchetkine@google.com> | 2011-02-07 14:14:14 -0800 |
---|---|---|
committer | Vladimir Chtchetkine <vchtchetkine@google.com> | 2011-02-07 14:49:09 -0800 |
commit | 17ecca637df2f573edc3ecb8246c0e38a5b32465 (patch) | |
tree | bc05a46566ad888b4659b048851b1e32a9fb5b92 /vl-android-ui.c | |
parent | 9af6946145bea73b16f1a128838048b917474f27 (diff) | |
download | external_qemu-17ecca637df2f573edc3ecb8246c0e38a5b32465.zip external_qemu-17ecca637df2f573edc3ecb8246c0e38a5b32465.tar.gz external_qemu-17ecca637df2f573edc3ecb8246c0e38a5b32465.tar.bz2 |
Fix emulator core and UI on Windows
There are two parts in this CL:
1. Fixing the Windows build (missing set_fd_handler)
2. Replacing read/write with socket_recv/socket_send.
Change-Id: I5fa599774260257d481b738a892e1124135fc319
Diffstat (limited to 'vl-android-ui.c')
-rw-r--r-- | vl-android-ui.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/vl-android-ui.c b/vl-android-ui.c index 6c0c934..0b63d4a 100644 --- a/vl-android-ui.c +++ b/vl-android-ui.c @@ -27,7 +27,14 @@ #define _GNU_SOURCE 1 #endif +#ifndef _WIN32 #include <sys/wait.h> +#endif // _WIN32 + +#ifdef _WIN32 +#include <windows.h> +#include <sys/timeb.h> +#endif #include "qemu-common.h" #include "net.h" @@ -54,6 +61,90 @@ static Looper* mainLooper; /***********************************************************/ +/* I/O handling */ + +typedef struct IOHandlerRecord { + LoopIo io[1]; + IOHandler* fd_read; + IOHandler* fd_write; + int running; + int deleted; + void* opaque; + struct IOHandlerRecord *next; +} IOHandlerRecord; + +static IOHandlerRecord *first_io_handler; + +static void ioh_callback(void* opaque, int fd, unsigned events) +{ + IOHandlerRecord* ioh = opaque; + ioh->running = 1; + if ((events & LOOP_IO_READ) != 0) { + ioh->fd_read(ioh->opaque); + } + if (!ioh->deleted && (events & LOOP_IO_WRITE) != 0) { + ioh->fd_write(ioh->opaque); + } + ioh->running = 0; + if (ioh->deleted) { + loopIo_done(ioh->io); + free(ioh); + } +} + +int qemu_set_fd_handler(int fd, + IOHandler *fd_read, + IOHandler *fd_write, + void *opaque) +{ + IOHandlerRecord **pioh, *ioh; + + if (!fd_read && !fd_write) { + pioh = &first_io_handler; + for(;;) { + ioh = *pioh; + if (ioh == NULL) + return 0; + if (ioh->io->fd == fd) { + break; + } + pioh = &ioh->next; + } + if (ioh->running) { + ioh->deleted = 1; + } else { + *pioh = ioh->next; + loopIo_done(ioh->io); + free(ioh); + } + } else { + for(ioh = first_io_handler; ioh != NULL; ioh = ioh->next) { + if (ioh->io->fd == fd) + goto found; + } + ANEW0(ioh); + ioh->next = first_io_handler; + first_io_handler = ioh; + loopIo_init(ioh->io, mainLooper, fd, ioh_callback, ioh); + found: + ioh->fd_read = fd_read; + ioh->fd_write = fd_write; + ioh->opaque = opaque; + + if (fd_read != NULL) + loopIo_wantRead(ioh->io); + else + loopIo_dontWantRead(ioh->io); + + if (fd_write != NULL) + loopIo_wantWrite(ioh->io); + else + loopIo_dontWantWrite(ioh->io); + } + return 0; +} + +/***********************************************************/ /* main execution loop */ static LoopTimer gui_timer[1]; |