]> git.pond.sub.org Git - empserver/commitdiff
Fix empth_select() for funny flag arguments
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 2 Feb 2009 07:08:38 +0000 (08:08 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 2 Feb 2009 07:08:38 +0000 (08:08 +0100)
EMPTH_POSIX and EMPTH_W32 implementations rejected values other than a
single flag.  Such values aren't used now, but it violates the
contract all the same.

src/lib/empthread/ntthread.c
src/lib/empthread/pthread.c

index 1279f732a1e27d751805e27b3d19aae7fbb34065..56f6db0a73e6482095430f8daa2afa565b94aea1 100644 (file)
@@ -565,6 +565,7 @@ empth_select(int fd, int flags, struct timeval *timeout)
 {
     int handle;
     WSAEVENT hEventObject[2];
 {
     int handle;
     WSAEVENT hEventObject[2];
+    long events;
     DWORD result, msec;
     empth_t *pThread = TlsGetValue(dwTLSIndex);
     int res;
     DWORD result, msec;
     empth_t *pThread = TlsGetValue(dwTLSIndex);
     int res;
@@ -579,21 +580,18 @@ empth_select(int fd, int flags, struct timeval *timeout)
     handle = posix_fd2socket(fd);
     CANT_HAPPEN(handle < 0);
 
     handle = posix_fd2socket(fd);
     CANT_HAPPEN(handle < 0);
 
-    if (flags == EMPTH_FD_READ)
-       WSAEventSelect(handle, hEventObject[0], FD_READ | FD_ACCEPT | FD_CLOSE);
-    else if (flags == EMPTH_FD_WRITE)
-       WSAEventSelect(handle, hEventObject[0], FD_WRITE | FD_CLOSE);
-    else {
-       logerror("bad flag %d passed to empth_select", flags);
-       empth_exit();
-    }
+    events = 0;
+    if (flags & EMPTH_FD_READ)
+       events |= FD_READ | FD_ACCEPT | FD_CLOSE;
+    if (flags & EMPTH_FD_WRITE)
+       events |= FD_WRITE | FD_CLOSE;
+    WSAEventSelect(handle, hEventObject[0], events);
 
     if (timeout)
        msec = timeout->tv_sec * 1000L + timeout->tv_usec / 1000L;
     else
        msec = WSA_INFINITE;
 
     if (timeout)
        msec = timeout->tv_sec * 1000L + timeout->tv_usec / 1000L;
     else
        msec = WSA_INFINITE;
-    result = WSAWaitForMultipleEvents(2, hEventObject, FALSE, msec,
-       FALSE);
+    result = WSAWaitForMultipleEvents(2, hEventObject, FALSE, msec, FALSE);
 
     switch (result) {
     case WSA_WAIT_TIMEOUT:
 
     switch (result) {
     case WSA_WAIT_TIMEOUT:
index 0f421ce952f3c1339f65348d6a86018f67668e07..7df1934d74991f4f58013c236a0e8a293c5d2dee 100644 (file)
@@ -299,25 +299,14 @@ empth_select(int fd, int flags, struct timeval *timeout)
     int res = 0;
 
     pthread_mutex_unlock(&mtx_ctxsw);
     int res = 0;
 
     pthread_mutex_unlock(&mtx_ctxsw);
-    empth_status("%s select on %d",
-                flags == EMPTH_FD_READ ? "read" : "write", fd);
+    empth_status("select on %d for %d", fd, flags);
 
     FD_ZERO(&readmask);
     FD_ZERO(&writemask);
 
     FD_ZERO(&readmask);
     FD_ZERO(&writemask);
-
-    switch (flags) {
-    case EMPTH_FD_READ:
+    if (flags & EMPTH_FD_READ)
        FD_SET(fd, &readmask);
        FD_SET(fd, &readmask);
-       break;
-    case EMPTH_FD_WRITE:
+    if (flags & EMPTH_FD_WRITE)
        FD_SET(fd, &writemask);
        FD_SET(fd, &writemask);
-       break;
-    default:
-       CANT_REACH();
-       errno = EINVAL;
-       res = -1;
-       goto done;
-    }
 
     if (timeout) {
        tv = *timeout;
 
     if (timeout) {
        tv = *timeout;
@@ -342,7 +331,6 @@ empth_select(int fd, int flags, struct timeval *timeout)
        res = 1;
     }
 
        res = 1;
     }
 
-done:
     pthread_mutex_lock(&mtx_ctxsw);
     empth_restorectx();
     return res;
     pthread_mutex_lock(&mtx_ctxsw);
     empth_restorectx();
     return res;