bjh 99/07/12 01:47:48
Modified: mpm/src/include ap_config.h mpm/src/os/os2 iol_socket.c util_os2.c Log: OS/2 EMX library's select() isn't thread safe so bypass it and go direct to the OS/2 API call. Unfortunately this only works on socket handles which will break probe_writable_fds() so I'll have to find a way to fix that too. Revision Changes Path 1.2 +2 -0 apache-2.0/mpm/src/include/ap_config.h Index: ap_config.h =================================================================== RCS file: /home/cvs/apache-2.0/mpm/src/include/ap_config.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ap_config.h 1999/06/18 18:39:27 1.1 +++ ap_config.h 1999/07/12 08:47:47 1.2 @@ -1163,6 +1163,8 @@ #elif defined(SELECT_NEEDS_CAST) #define ap_select(_a, _b, _c, _d, _e) \ select((_a), (int *)(_b), (int *)(_c), (int *)(_d), (_e)) +#elif defined(OS2) +int ap_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); #else #define ap_select(_a, _b, _c, _d, _e) \ select(_a, _b, _c, _d, _e) 1.2 +1 -1 apache-2.0/mpm/src/os/os2/iol_socket.c Index: iol_socket.c =================================================================== RCS file: /home/cvs/apache-2.0/mpm/src/os/os2/iol_socket.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- iol_socket.c 1999/07/11 14:49:07 1.1 +++ iol_socket.c 1999/07/12 08:47:47 1.2 @@ -140,7 +140,7 @@ tv.tv_sec = iol->timeout; \ tv.tv_usec = 0; \ do { \ - rv = select(iol->fd + 1, selread, selwrite, NULL, iol->timeout < 0 ? NULL : &tv); \ + rv = ap_select(iol->fd + 1, selread, selwrite, NULL, iol->timeout < 0 ? NULL : &tv); \ } while (rv == -1 && errno == EINTR); \ if (!FD_ISSET(iol->fd, &fdset)) { \ errno = ETIMEDOUT; \ 1.3 +91 -0 apache-2.0/mpm/src/os/os2/util_os2.c Index: util_os2.c =================================================================== RCS file: /home/cvs/apache-2.0/mpm/src/os/os2/util_os2.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- util_os2.c 1999/07/11 14:49:07 1.2 +++ util_os2.c 1999/07/12 08:47:48 1.3 @@ -94,3 +94,94 @@ return result; } + + + + +int (*os2_select)( int *, int, int, int, long ) = NULL; +static HMODULE hSO32DLL; + +int ap_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) +{ + int *fds, s, fd_count=0, rc; + int num_read, num_write, num_except; + long ms_timeout = -1; + + if (os2_select == NULL) { + DosEnterCritSec(); /* Stop two threads doing this at the same time */ + + if (os2_select == NULL) { + hSO32DLL = ap_os_dso_load("SO32DLL"); + + if (hSO32DLL) { + os2_select = ap_os_dso_sym(hSO32DLL, "SELECT"); + } + } + DosExitCritSec(); + } + + ap_assert(os2_select != NULL); + fds = alloca(sizeof(int) * nfds); + + if (readfds) { + for (s=0; s<nfds; s++) + if (FD_ISSET(s, readfds)) + fds[fd_count++] = _getsockhandle(s); + } + + num_read = fd_count; + + if (writefds) { + for (s=0; s<nfds; s++) + if (FD_ISSET(s, writefds)) + fds[fd_count++] = _getsockhandle(s); + } + + num_write = fd_count - num_read; + + if (exceptfds) { + for (s=0; s<nfds; s++) + if (FD_ISSET(s, exceptfds)) + fds[fd_count++] = _getsockhandle(s); + } + + num_except = fd_count - num_read - num_write; + + if (timeout) + ms_timeout = timeout->tv_usec / 1000 + timeout->tv_sec * 1000; + + rc = os2_select(fds, num_read, num_write, num_except, ms_timeout); + + if (rc > 0) { + fd_count = 0; + + if (readfds) { + for (s=0; s<nfds; s++) { + if (FD_ISSET(s, readfds)) { + if (fds[fd_count++] < 0) + FD_CLR(s, readfds); + } + } + } + + if (writefds) { + for (s=0; s<nfds; s++) { + if (FD_ISSET(s, writefds)) { + if (fds[fd_count++] < 0) + FD_CLR(s, writefds); + } + } + } + + if (exceptfds) { + for (s=0; s<nfds; s++) { + if (FD_ISSET(s, exceptfds)) { + if (fds[fd_count++] < 0) + FD_CLR(s, exceptfds); + } + } + } + } + + return rc; +}