Introduce xcb_wait_for_event_until, for consuming responses in wire-order.
[free-sw/xcb/libxcb] / src / xcb_conn.c
index ebaa6e2..a017c20 100644 (file)
@@ -58,7 +58,7 @@ typedef struct {
     uint16_t length;
 } xcb_setup_generic_t;
 
-static const int error_connection = 1;
+const int error_connection = 1;
 
 static int set_fd_flags(const int fd)
 {
@@ -257,6 +257,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
 {
     xcb_connection_t* c;
 
+#ifndef _WIN32
 #ifndef USE_POLL
     if(fd >= FD_SETSIZE) /* would overflow in FD_SET */
     {
@@ -264,6 +265,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
         return (xcb_connection_t *) &error_connection;
     }
 #endif
+#endif /* !_WIN32*/
 
     c = calloc(1, sizeof(xcb_connection_t));
     if(!c) {
@@ -293,7 +295,7 @@ xcb_connection_t *xcb_connect_to_fd(int fd, xcb_auth_info_t *auth_info)
 
 void xcb_disconnect(xcb_connection_t *c)
 {
-    if(c->has_error)
+    if(c == (xcb_connection_t *) &error_connection)
         return;
 
     free(c->setup);
@@ -364,6 +366,13 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vec
     do {
 #if USE_POLL
         ret = poll(&fd, 1, -1);
+        /* If poll() returns an event we didn't expect, such as POLLNVAL, treat
+         * it as if it failed. */
+        if(ret >= 0 && (fd.revents & ~fd.events))
+        {
+            ret = -1;
+            break;
+        }
 #else
         ret = select(c->fd + 1, &rfds, &wfds, 0, 0);
 #endif