--- libxcb-1.1/configure.ac.poll 2009-02-25 19:38:56.000000000 -0800 +++ libxcb-1.1/configure.ac 2009-02-25 19:38:56.000000000 -0800 @@ -86,6 +86,8 @@ ])]) AM_CHECK_DOXYGEN() +AC_CHECK_FUNC(poll, [AC_DEFINE(USE_POLL, 1, [poll() function is available])], ) + AC_CONFIG_FILES([Makefile src/Makefile tests/Makefile doc/Makefile]) AC_CONFIG_FILES([xcb.pc xcb-xlib.pc xcb-composite.pc xcb-damage.pc xcb-dpms.pc xcb-glx.pc xcb-randr.pc xcb-record.pc xcb-render.pc xcb-res.pc xcb-screensaver.pc xcb-shape.pc xcb-shm.pc xcb-sync.pc xcb-xevie.pc xcb-xf86dri.pc xcb-xfixes.pc xcb-xinerama.pc xcb-xprint.pc xcb-xtest.pc xcb-xv.pc xcb-xvmc.pc]) AC_CONFIG_FILES([doc/xcb.doxygen]) --- libxcb-1.1/src/xcb_conn.c.poll 2009-02-25 19:38:56.000000000 -0800 +++ libxcb-1.1/src/xcb_conn.c 2009-02-25 19:41:11.000000000 -0800 @@ -31,12 +31,16 @@ #include #include #include -#include #include #include #include "xcb.h" #include "xcbint.h" +#if USE_POLL +#include +#else +#include +#endif typedef struct { uint8_t status; @@ -309,7 +313,11 @@ int _xcb_conn_wait(xcb_connection_t *c, pthread_cond_t *cond, struct iovec **vector, int *count) { int ret, xlib_locked; +#if USE_POLL + struct pollfd fd; +#else fd_set rfds, wfds; +#endif /* If the thing I should be doing is already being done, wait for it. */ if(count ? c->out.writing : c->in.reading) @@ -318,16 +326,30 @@ return 1; } +#if USE_POLL + memset(&fd, 0, sizeof(fd)); + fd.fd = c->fd; + fd.events = POLLIN; +#else FD_ZERO(&rfds); FD_SET(c->fd, &rfds); +#endif ++c->in.reading; +#if USE_POLL + if(count) + { + fd.events |= POLLOUT; + ++c->out.writing; + } +#else FD_ZERO(&wfds); if(count) { FD_SET(c->fd, &wfds); ++c->out.writing; } +#endif xlib_locked = c->xlib.lock; if(xlib_locked) @@ -337,7 +359,11 @@ } _xcb_unlock_io(c); do { +#if USE_POLL + ret = poll(&fd, 1, -1); +#else ret = select(c->fd + 1, &rfds, &wfds, 0, 0); +#endif } while (ret == -1 && errno == EINTR); if (ret < 0) { @@ -353,10 +379,18 @@ if(ret) { +#if USE_POLL + if((fd.revents & POLLIN) == POLLIN) +#else if(FD_ISSET(c->fd, &rfds)) +#endif ret = ret && _xcb_in_read(c); +#if USE_POLL + if((fd.revents & POLLOUT) == POLLOUT) +#else if(FD_ISSET(c->fd, &wfds)) +#endif ret = ret && write_vec(c, vector, count); } --- libxcb-1.1/src/xcb_in.c.poll 2007-10-23 09:44:59.000000000 -0700 +++ libxcb-1.1/src/xcb_in.c 2009-02-26 10:03:25.000000000 -0800 @@ -30,12 +30,16 @@ #include #include #include -#include #include #include "xcb.h" #include "xcbext.h" #include "xcbint.h" +#if USE_POLL +#include +#else +#include +#endif #define XCB_ERROR 0 #define XCB_REPLY 1 @@ -241,12 +245,22 @@ done += ret; if(ret < 0 && errno == EAGAIN) { +#if USE_POLL + struct pollfd pfd; + pfd.fd = fd; + pfd.events = POLLIN; + pfd.revents = 0; + do { + ret = poll(&pfd, 1, -1); + } while (ret == -1 && errno == EINTR); +#else fd_set fds; FD_ZERO(&fds); FD_SET(fd, &fds); do { ret = select(fd + 1, &fds, 0, 0, 0); } while (ret == -1 && errno == EINTR); +#endif } if(ret <= 0) return ret;