Fix empth_select() for funny flag arguments
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.
This commit is contained in:
parent
cd740c1b63
commit
48cec49fbf
2 changed files with 11 additions and 25 deletions
|
@ -565,6 +565,7 @@ empth_select(int fd, int flags, struct timeval *timeout)
|
||||||
{
|
{
|
||||||
int handle;
|
int handle;
|
||||||
WSAEVENT hEventObject[2];
|
WSAEVENT hEventObject[2];
|
||||||
|
long events;
|
||||||
DWORD result, msec;
|
DWORD result, msec;
|
||||||
empth_t *pThread = TlsGetValue(dwTLSIndex);
|
empth_t *pThread = TlsGetValue(dwTLSIndex);
|
||||||
int res;
|
int res;
|
||||||
|
@ -579,21 +580,18 @@ empth_select(int fd, int flags, struct timeval *timeout)
|
||||||
handle = posix_fd2socket(fd);
|
handle = posix_fd2socket(fd);
|
||||||
CANT_HAPPEN(handle < 0);
|
CANT_HAPPEN(handle < 0);
|
||||||
|
|
||||||
if (flags == EMPTH_FD_READ)
|
events = 0;
|
||||||
WSAEventSelect(handle, hEventObject[0], FD_READ | FD_ACCEPT | FD_CLOSE);
|
if (flags & EMPTH_FD_READ)
|
||||||
else if (flags == EMPTH_FD_WRITE)
|
events |= FD_READ | FD_ACCEPT | FD_CLOSE;
|
||||||
WSAEventSelect(handle, hEventObject[0], FD_WRITE | FD_CLOSE);
|
if (flags & EMPTH_FD_WRITE)
|
||||||
else {
|
events |= FD_WRITE | FD_CLOSE;
|
||||||
logerror("bad flag %d passed to empth_select", flags);
|
WSAEventSelect(handle, hEventObject[0], events);
|
||||||
empth_exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timeout)
|
if (timeout)
|
||||||
msec = timeout->tv_sec * 1000L + timeout->tv_usec / 1000L;
|
msec = timeout->tv_sec * 1000L + timeout->tv_usec / 1000L;
|
||||||
else
|
else
|
||||||
msec = WSA_INFINITE;
|
msec = WSA_INFINITE;
|
||||||
result = WSAWaitForMultipleEvents(2, hEventObject, FALSE, msec,
|
result = WSAWaitForMultipleEvents(2, hEventObject, FALSE, msec, FALSE);
|
||||||
FALSE);
|
|
||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case WSA_WAIT_TIMEOUT:
|
case WSA_WAIT_TIMEOUT:
|
||||||
|
|
|
@ -299,25 +299,14 @@ empth_select(int fd, int flags, struct timeval *timeout)
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
pthread_mutex_unlock(&mtx_ctxsw);
|
pthread_mutex_unlock(&mtx_ctxsw);
|
||||||
empth_status("%s select on %d",
|
empth_status("select on %d for %d", fd, flags);
|
||||||
flags == EMPTH_FD_READ ? "read" : "write", fd);
|
|
||||||
|
|
||||||
FD_ZERO(&readmask);
|
FD_ZERO(&readmask);
|
||||||
FD_ZERO(&writemask);
|
FD_ZERO(&writemask);
|
||||||
|
if (flags & EMPTH_FD_READ)
|
||||||
switch (flags) {
|
|
||||||
case EMPTH_FD_READ:
|
|
||||||
FD_SET(fd, &readmask);
|
FD_SET(fd, &readmask);
|
||||||
break;
|
if (flags & EMPTH_FD_WRITE)
|
||||||
case EMPTH_FD_WRITE:
|
|
||||||
FD_SET(fd, &writemask);
|
FD_SET(fd, &writemask);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
CANT_REACH();
|
|
||||||
errno = EINVAL;
|
|
||||||
res = -1;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
tv = *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);
|
pthread_mutex_lock(&mtx_ctxsw);
|
||||||
empth_restorectx();
|
empth_restorectx();
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue