Set errno=0 in read_block. On Win32 there is no errno and this makes the
[free-sw/xcb/libxcb] / src / xcb_in.c
index 20ff4f2..b481295 100644 (file)
 #include "xcbint.h"
 #if USE_POLL
 #include <poll.h>
-#elif !defined WIN32
+#elif !defined _WIN32
 #include <sys/select.h>
 #endif
 
 #ifdef _WIN32
-#include "windefs.h"
+#include "xcb_windefs.h"
 #endif /* _WIN32 */
 
 #define XCB_ERROR 0
@@ -286,7 +286,6 @@ static int read_block(const int fd, void *buf, const ssize_t len)
 #endif /* !_Win32 */
         {
 #if USE_POLL
-#ifndef _WIN32
             struct pollfd pfd;
             pfd.fd = fd;
             pfd.events = POLLIN;
@@ -294,20 +293,16 @@ static int read_block(const int fd, void *buf, const ssize_t len)
             do {
                 ret = poll(&pfd, 1, -1);
             } while (ret == -1 && errno == EINTR);
-#endif /* !_WIN32 */
 #else
             fd_set fds;
             FD_ZERO(&fds);
             FD_SET(fd, &fds);
-#ifndef _WIN32
+
+           /* Initializing errno here makes sure that for Win32 this loop will execute only once */
+           errno = 0;  
            do {
                ret = select(fd + 1, &fds, 0, 0, 0);
            } while (ret == -1 && errno == EINTR);
-#else
-           /* the do while loop used for the non-windows version isn't required*/
-           /* for windows since there are no signals in Windows hence no EINTR*/           
-           ret = select(fd + 1, &fds, 0, 0, 0);
-#endif /* !_WIN32 */
 #endif /* USE_POLL */
         }
         if(ret <= 0)