Replace my old generic map ADT with a growable array for the extension cache.
[free-sw/xcb/libxcb] / src / xcb_in.c
index ead0178..6f084ba 100644 (file)
@@ -153,6 +153,27 @@ static int read_packet(XCBConnection *c)
     return 1; /* I have something for you... */
 }
 
+static int read_block(const int fd, void *buf, const size_t len)
+{
+    int done = 0;
+    while(done < len)
+    {
+        int ret = read(fd, ((char *) buf) + done, len - done);
+        if(ret > 0)
+            done += ret;
+        if(ret < 0 && errno == EAGAIN)
+        {
+            fd_set fds;
+            FD_ZERO(&fds);
+            FD_SET(fd, &fds);
+            ret = select(fd + 1, &fds, 0, 0, 0);
+        }
+        if(ret <= 0)
+            return ret;
+    }
+    return len;
+}
+
 /* Public interface */
 
 void *XCBWaitForReply(XCBConnection *c, unsigned int request, XCBGenericError **e)
@@ -222,11 +243,6 @@ XCBGenericEvent *XCBWaitEvent(XCBConnection *c)
 XCBGenericEvent *XCBWaitForEvent(XCBConnection *c)
 {
     XCBGenericEvent *ret;
-
-#if XCBTRACEEVENT
-    fprintf(stderr, "Entering XCBWaitEvent\n");
-#endif
-
     pthread_mutex_lock(&c->iolock);
     /* _xcb_list_remove_head returns 0 on empty list. */
     while(!(ret = _xcb_queue_dequeue(c->in.events)))
@@ -235,11 +251,6 @@ XCBGenericEvent *XCBWaitForEvent(XCBConnection *c)
 
     wake_up_next_reader(c);
     pthread_mutex_unlock(&c->iolock);
-
-#if XCBTRACEEVENT
-    fprintf(stderr, "Leaving XCBWaitEvent, event type %d\n", ret ? ret->response_type : -1);
-#endif
-
     return ret;
 }
 
@@ -348,7 +359,7 @@ int _xcb_in_read_block(XCBConnection *c, void *buf, int len)
 
     if(len > done)
     {
-        int ret = _xcb_read_block(c->fd, (char *) buf + done, len - done);
+        int ret = read_block(c->fd, (char *) buf + done, len - done);
         if(ret <= 0)
             return ret;
     }