[PATCH 2/2] Test WaitForSomething select return in new Check* functions

Keith Packard keithp at keithp.com
Wed Jun 20 12:09:08 PDT 2012


The bitmask from select is only valid if it returned a positive value,
so record it for use by CheckWriteSocket and CheckReadSocket

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 os/WaitFor.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/os/WaitFor.c b/os/WaitFor.c
index 537d678..41a60c1 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -126,6 +126,7 @@ static OsTimerPtr timers = NULL;
 static fd_set WriteSelectMask;
 static Bool AnyWriteSelectMask;
 static fd_set LastSelectWriteMask;
+static int LastSelectReturn;
 
 /*****************
  * AddWriteSocket:
@@ -168,7 +169,7 @@ RemoveWriteSocket(int fd)
 Bool
 CheckWriteSocket(int fd)
 {
-    return AnyWriteSelectMask && FD_ISSET(fd, &LastSelectWriteMask);
+    return LastSelectReturn > 0 && AnyWriteSelectMask && FD_ISSET(fd, &LastSelectWriteMask);
 }
 
 /*****************
@@ -184,7 +185,7 @@ CheckWriteSocket(int fd)
 Bool
 CheckReadSocket(int fd)
 {
-    return FD_ISSET(fd, &LastSelectMask);
+    return LastSelectReturn > 0 && FD_ISSET(fd, &LastSelectMask);
 }
 
 
@@ -287,6 +288,7 @@ WaitForSomething(int *pClientsReady)
             i = Select(MaxClients, &LastSelectMask, NULL, NULL, wt);
         }
         selecterr = GetErrno();
+        LastSelectReturn = i;
         WakeupHandler(i, (pointer) &LastSelectMask);
         if (i <= 0) {           /* An error or timeout occurred */
             if (dispatchException)
-- 
1.7.10



More information about the xorg-devel mailing list