diff options
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | apr.dsp | 4 | ||||
-rw-r--r-- | include/arch/unix/apr_arch_poll_private.h | 4 | ||||
-rw-r--r-- | include/arch/win32/apr_arch_misc.h | 34 | ||||
-rw-r--r-- | libapr.dsp | 4 | ||||
-rw-r--r-- | poll/unix/poll.c | 28 | ||||
-rw-r--r-- | poll/unix/select.c | 6 |
7 files changed, 81 insertions, 3 deletions
@@ -1,6 +1,10 @@ -*- coding: utf-8 -*- Changes for APR 2.0.0 + *) Win32: Use WSAPoll as default pollset method if supported and + found inside winsock dll. + [Mladen Turk] + *) Make apr_pollset and apr_pollcb implementations using providers. Added apr_pollset_create_ex and apr_pollcb_create_ex that allows choosing non-default providers. @@ -420,6 +420,10 @@ SOURCE=.\poll\unix\pollset.c # End Source File # Begin Source File +SOURCE=.\poll\unix\poll.c +# End Source File +# Begin Source File + SOURCE=.\poll\unix\select.c # End Source File # End Group diff --git a/include/arch/unix/apr_arch_poll_private.h b/include/arch/unix/apr_arch_poll_private.h index c2e646b46..48fe30436 100644 --- a/include/arch/unix/apr_arch_poll_private.h +++ b/include/arch/unix/apr_arch_poll_private.h @@ -63,11 +63,15 @@ #define POLLSET_DEFAULT_METHOD APR_POLLSET_SELECT #endif +#ifdef WIN32 +#define POLL_USES_SELECT +#else #ifdef HAVE_POLL #define POLL_USES_POLL #else #define POLL_USES_SELECT #endif +#endif #if defined(POLLSET_USES_KQUEUE) || defined(POLLSET_USES_EPOLL) || defined(POLLSET_USES_PORT) diff --git a/include/arch/win32/apr_arch_misc.h b/include/arch/win32/apr_arch_misc.h index c7d1cb3c8..eac6cb5dd 100644 --- a/include/arch/win32/apr_arch_misc.h +++ b/include/arch/win32/apr_arch_misc.h @@ -436,6 +436,40 @@ APR_DECLARE_LATE_DLL_FUNC(DLL_WINBASEAPI, BOOL, WINAPI, Process32NextW, 0, ( (hSnapshot, lppe)); #define Process32NextW apr_winapi_Process32NextW +#if !defined(POLLERR) +/* Event flag definitions for WSAPoll(). */ +#define POLLRDNORM 0x0100 +#define POLLRDBAND 0x0200 +#define POLLIN (POLLRDNORM | POLLRDBAND) +#define POLLPRI 0x0400 + +#define POLLWRNORM 0x0010 +#define POLLOUT (POLLWRNORM) +#define POLLWRBAND 0x0020 + +#define POLLERR 0x0001 +#define POLLHUP 0x0002 +#define POLLNVAL 0x0004 + +typedef struct pollfd { + SOCKET fd; + SHORT events; + SHORT revents; + +} WSAPOLLFD, *PWSAPOLLFD, FAR *LPWSAPOLLFD; + +#endif /* !defined(POLLERR) */ +#ifdef WSAPoll +#undef WSAPoll +#endif +APR_DECLARE_LATE_DLL_FUNC(DLL_WINSOCK2API, int, WSAAPI, WSAPoll, 0, ( + IN OUT LPWSAPOLLFD fdArray, + IN ULONG fds, + IN INT timeout), + (fdArray, fds, timeout)); +#define WSAPoll apr_winapi_WSAPoll +#define HAVE_POLL 1 + #endif /* !defined(_WIN32_WCE) */ #endif /* ! MISC_H */ diff --git a/libapr.dsp b/libapr.dsp index 485f1c761..a5d3db4b3 100644 --- a/libapr.dsp +++ b/libapr.dsp @@ -472,6 +472,10 @@ SOURCE=.\poll\unix\pollset.c # End Source File # Begin Source File +SOURCE=.\poll\unix\poll.c +# End Source File +# Begin Source File + SOURCE=.\poll\unix\select.c # End Source File # End Group diff --git a/poll/unix/poll.c b/poll/unix/poll.c index 18bd893dc..bd24efb08 100644 --- a/poll/unix/poll.c +++ b/poll/unix/poll.c @@ -167,6 +167,11 @@ static apr_status_t impl_pollset_create(apr_pollset_t *pollset, if (flags & APR_POLLSET_THREADSAFE) { return APR_ENOTIMPL; } +#ifdef WIN32 + if (!APR_HAVE_LATE_DLL_FUNC(WSAPoll)) { + return APR_ENOTIMPL; + } +#endif pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t)); pollset->p->pollset = apr_palloc(p, size * sizeof(struct pollfd)); pollset->p->query_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); @@ -188,9 +193,16 @@ static apr_status_t impl_pollset_add(apr_pollset_t *pollset, pollset->p->pollset[pollset->nelts].fd = descriptor->desc.s->socketdes; } else { +#if APR_FILES_AS_SOCKETS pollset->p->pollset[pollset->nelts].fd = descriptor->desc.f->filedes; +#else + if ((pollset->flags & APR_POLLSET_WAKEABLE) && + descriptor->desc.f == pollset->wakeup_pipe[0]) + pollset->p->pollset[pollset->nelts].fd = (SOCKET)descriptor->desc.f->filedes; + else + return APR_EBADF; +#endif } - pollset->p->pollset[pollset->nelts].events = get_event(descriptor->reqevents); pollset->nelts++; @@ -238,7 +250,11 @@ static apr_status_t impl_pollset_poll(apr_pollset_t *pollset, if (timeout > 0) { timeout /= 1000; } +#ifdef WIN32 + ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout); +#else ret = poll(pollset->p->pollset, pollset->nelts, timeout); +#endif (*num) = ret; if (ret < 0) { return apr_get_netos_error(); @@ -311,7 +327,11 @@ static apr_status_t impl_pollcb_add(apr_pollcb_t *pollcb, pollcb->pollset.ps[pollcb->nelts].fd = descriptor->desc.s->socketdes; } else { +#if APR_FILES_AS_SOCKETS pollcb->pollset.ps[pollcb->nelts].fd = descriptor->desc.f->filedes; +#else + return APR_EBADF; +#endif } pollcb->pollset.ps[pollcb->nelts].events = @@ -357,12 +377,16 @@ static apr_status_t impl_pollcb_poll(apr_pollcb_t *pollcb, { int ret; apr_status_t rv = APR_SUCCESS; - apr_uint32_t i, j; + apr_uint32_t i; if (timeout > 0) { timeout /= 1000; } +#ifdef WIN32 + ret = WSAPoll(pollcb->pollset.ps, pollcb->nelts, (int)timeout); +#else ret = poll(pollcb->pollset.ps, pollcb->nelts, timeout); +#endif if (ret < 0) { return apr_get_netos_error(); } diff --git a/poll/unix/select.c b/poll/unix/select.c index 736388bb6..1affe8151 100644 --- a/poll/unix/select.c +++ b/poll/unix/select.c @@ -233,7 +233,11 @@ static apr_status_t impl_pollset_add(apr_pollset_t *pollset, } else { #if !APR_FILES_AS_SOCKETS - return APR_EBADF; + if ((pollset->flags & APR_POLLSET_WAKEABLE) && + descriptor->desc.f == pollset->wakeup_pipe[0]) + fd = (apr_os_sock_t)descriptor->desc.f->filedes; + else + return APR_EBADF; #else #ifdef NETWARE /* NetWare can't handle mixed descriptor types in select() */ |