Index: ioemu/vnc.c
===================================================================
--- ioemu.orig/vnc.c	2006-08-17 19:37:36.091553839 +0100
+++ ioemu/vnc.c	2006-08-17 19:50:10.313996001 +0100
@@ -143,13 +143,16 @@
 static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
 {
     VncState *vs = ds->opaque;
-    int i;
+    uint64_t mask;
 
     h += y;
+    if (w != 1024)
+	mask = ((1ULL << (w / 16)) - 1) << (x / 16);
+    else
+	mask = ~(0ULL);
 
     for (; y < h; y++)
-	for (i = 0; i < w; i += 16)
-	    vnc_set_bit(vs->dirty_row[y], (x + i) / 16);
+	vs->dirty_row[y] |= mask;
 }
 
 static void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
@@ -373,6 +376,7 @@
 static void vnc_update_client(void *opaque)
 {
     VncState *vs = opaque;
+    int64_t now = qemu_get_clock(rt_clock);
 
     if (vs->need_update && vs->csock != -1) {
 	int y;
@@ -390,7 +394,7 @@
 	row = vs->ds->data;
 	old_row = vs->old_data;
 
-	for (y = 0; y < vs->height; y++) {
+	for (y = 0; y < vs->ds->height; y++) {
 	    if (vnc_and_bits(vs->dirty_row[y], width_mask, VNC_DIRTY_WORDS)) {
 		int x;
 		char *ptr, *old_ptr;
@@ -415,10 +419,8 @@
 	    old_row += vs->ds->linesize;
 	}
 
-	if (!has_dirty) {
-	    qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL);
-	    return;
-	}
+	if (!has_dirty)
+	    goto out;
 
 	/* Count rectangles */
 	n_rectangles = 0;
@@ -456,7 +458,9 @@
 	vnc_flush(vs);
 
     }
-    qemu_mod_timer(vs->timer, qemu_get_clock(rt_clock) + VNC_REFRESH_INTERVAL);
+
+ out:
+    qemu_mod_timer(vs->timer, now + VNC_REFRESH_INTERVAL);
 }
 
 static void vnc_timer_init(VncState *vs)
Index: ioemu/vl.c
===================================================================
--- ioemu.orig/vl.c	2006-08-17 19:50:02.410869542 +0100
+++ ioemu/vl.c	2006-08-17 19:50:10.316995669 +0100
@@ -5120,10 +5120,10 @@
         /* XXX: better handling of removal */
         for(ioh = first_io_handler; ioh != NULL; ioh = ioh_next) {
             ioh_next = ioh->next;
-            if (FD_ISSET(ioh->fd, &rfds)) {
+            if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) {
                 ioh->fd_read(ioh->opaque);
             }
-            if (FD_ISSET(ioh->fd, &wfds)) {
+            if (ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) {
                 ioh->fd_write(ioh->opaque);
             }
         }
