You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by tr...@apache.org on 2011/04/29 14:51:20 UTC
svn commit: r1097797 - in /apr/apr/branches/1.4.x: CHANGES
include/apr_poll.h poll/unix/poll.c poll/unix/select.c test/testpoll.c
Author: trawick
Date: Fri Apr 29 12:51:20 2011
New Revision: 1097797
URL: http://svn.apache.org/viewvc?rev=1097797&view=rev
Log:
>From trunk:
1. r1089433
poll, pollset, pollcb on Windows: Handle calls with no file/socket
descriptors.
PR: 49882
Patch for one situation submitted by: Stefan Ruppert <sr myarm.com>
Extended by: trawick
2. r1089528
fix variable initialization bug in r1089433
3. r987639
disable entire impl_pollcb_create() function if APR_HAS_THREADS
instead of just inserting a return at the top
4. tiny part of r899905
move decl of loop control variables to the block where used
--/--
Not in trunk or 1.5.x branch:
Add @bug notice to apr_poll()/apr_pollset_poll()/apr_pollcb_poll()
mentioning the Windows problem in versions 1.4.2 and prior.
Modified:
apr/apr/branches/1.4.x/CHANGES
apr/apr/branches/1.4.x/include/apr_poll.h
apr/apr/branches/1.4.x/poll/unix/poll.c
apr/apr/branches/1.4.x/poll/unix/select.c
apr/apr/branches/1.4.x/test/testpoll.c
Modified: apr/apr/branches/1.4.x/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/CHANGES?rev=1097797&r1=1097796&r2=1097797&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/CHANGES [utf-8] (original)
+++ apr/apr/branches/1.4.x/CHANGES [utf-8] Fri Apr 29 12:51:20 2011
@@ -1,6 +1,9 @@
-*- coding: utf-8 -*-
Changes for APR 1.4.3
+ *) poll, pollset, pollcb on Windows: Handle calls with no file/socket
+ descriptors. PR 49882. [Stefan Ruppert <sr myarm.com>, Jeff Trawick]
+
*) Fix APR_IPV6_V6ONLY issues on Windows related to run-time behavior
on Windows older than Vista and SDK/MinGW levels without IPV6_V6ONLY.
PR 45321. [Sob <sob hisoftware.cz>]
Modified: apr/apr/branches/1.4.x/include/apr_poll.h
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/include/apr_poll.h?rev=1097797&r1=1097796&r2=1097797&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/include/apr_poll.h (original)
+++ apr/apr/branches/1.4.x/include/apr_poll.h Fri Apr 29 12:51:20 2011
@@ -259,6 +259,8 @@ APR_DECLARE(apr_status_t) apr_pollset_re
* @remark Multiple signalled conditions for the same descriptor may be reported
* in one or more returned apr_pollfd_t structures, depending on the
* implementation.
+ * @bug With versions 1.4.2 and prior on Windows, a call with no descriptors
+ * and timeout will return immediately with the wrong error code.
*/
APR_DECLARE(apr_status_t) apr_pollset_poll(apr_pollset_t *pollset,
apr_interval_time_t timeout,
@@ -288,6 +290,8 @@ APR_DECLARE(apr_status_t) apr_pollset_wa
* descriptor has been signalled or the timeout has expired.
* @remark The rtnevents field in the apr_pollfd_t array will only be filled-
* in if the return value is APR_SUCCESS.
+ * @bug With versions 1.4.2 and prior on Windows, a call with no descriptors
+ * and timeout will return immediately with the wrong error code.
*/
APR_DECLARE(apr_status_t) apr_poll(apr_pollfd_t *aprset, apr_int32_t numsock,
apr_int32_t *nsds,
@@ -393,6 +397,8 @@ typedef apr_status_t (*apr_pollcb_cb_t)(
* @remark Multiple signalled conditions for the same descriptor may be reported
* in one or more calls to the callback function, depending on the
* implementation.
+ * @bug With versions 1.4.2 and prior on Windows, a call with no descriptors
+ * and timeout will return immediately with the wrong error code.
*/
APR_DECLARE(apr_status_t) apr_pollcb_poll(apr_pollcb_t *pollcb,
apr_interval_time_t timeout,
Modified: apr/apr/branches/1.4.x/poll/unix/poll.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/poll/unix/poll.c?rev=1097797&r1=1097796&r2=1097797&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/poll/unix/poll.c (original)
+++ apr/apr/branches/1.4.x/poll/unix/poll.c Fri Apr 29 12:51:20 2011
@@ -240,12 +240,24 @@ static apr_status_t impl_pollset_poll(ap
{
int ret;
apr_status_t rv = APR_SUCCESS;
- apr_uint32_t i, j;
+#ifdef WIN32
+ apr_interval_time_t orig_timeout = timeout;
+#endif
if (timeout > 0) {
timeout /= 1000;
}
#ifdef WIN32
+ /* WSAPoll() requires at least one socket. */
+ if (pollset->nelts == 0) {
+ *num = 0;
+ if (orig_timeout > 0) {
+ apr_sleep(orig_timeout);
+ return APR_TIMEUP;
+ }
+ return APR_SUCCESS;
+ }
+
ret = WSAPoll(pollset->p->pollset, pollset->nelts, (int)timeout);
#else
ret = poll(pollset->p->pollset, pollset->nelts, timeout);
@@ -258,6 +270,8 @@ static apr_status_t impl_pollset_poll(ap
return APR_TIMEUP;
}
else {
+ apr_uint32_t i, j;
+
for (i = 0, j = 0; i < pollset->nelts; i++) {
if (pollset->p->pollset[i].revents != 0) {
/* Check if the polled descriptor is our
@@ -305,9 +319,8 @@ static apr_status_t impl_pollcb_create(a
apr_uint32_t flags)
{
#if APR_HAS_THREADS
- return APR_ENOTIMPL;
-#endif
-
+ return APR_ENOTIMPL;
+#else
pollcb->fd = -1;
#ifdef WIN32
if (!APR_HAVE_LATE_DLL_FUNC(WSAPoll)) {
@@ -319,6 +332,7 @@ static apr_status_t impl_pollcb_create(a
pollcb->copyset = apr_palloc(p, size * sizeof(apr_pollfd_t *));
return APR_SUCCESS;
+#endif
}
static apr_status_t impl_pollcb_add(apr_pollcb_t *pollcb,
Modified: apr/apr/branches/1.4.x/poll/unix/select.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/poll/unix/select.c?rev=1097797&r1=1097796&r2=1097797&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/poll/unix/select.c (original)
+++ apr/apr/branches/1.4.x/poll/unix/select.c Fri Apr 29 12:51:20 2011
@@ -41,6 +41,21 @@ APR_DECLARE(apr_status_t) apr_poll(apr_p
apr_datatype_e set_type = APR_NO_DESC;
#endif
+#ifdef WIN32
+ /* On Win32, select() must be presented with at least one socket to
+ * poll on, or select() will return WSAEINVAL. So, we'll just
+ * short-circuit and bail now.
+ */
+ if (num == 0) {
+ (*nsds) = 0;
+ if (timeout > 0) {
+ apr_sleep(timeout);
+ return APR_TIMEUP;
+ }
+ return APR_SUCCESS;
+ }
+#endif
+
if (timeout < 0) {
tvptr = NULL;
}
@@ -339,6 +354,10 @@ static apr_status_t impl_pollset_poll(ap
*/
if (pollset->nelts == 0) {
(*num) = 0;
+ if (timeout > 0) {
+ apr_sleep(timeout);
+ return APR_TIMEUP;
+ }
return APR_SUCCESS;
}
#endif
Modified: apr/apr/branches/1.4.x/test/testpoll.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/test/testpoll.c?rev=1097797&r1=1097796&r2=1097797&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/test/testpoll.c (original)
+++ apr/apr/branches/1.4.x/test/testpoll.c Fri Apr 29 12:51:20 2011
@@ -769,6 +769,69 @@ static void pollcb_default(abts_case *tc
}
}
+static void justsleep(abts_case *tc, void *data)
+{
+ apr_int32_t nsds;
+ const apr_pollfd_t *hot_files;
+ apr_pollset_t *pollset;
+ apr_status_t rv;
+ apr_time_t t1, t2;
+ int i;
+ apr_pollset_method_e methods[] = {
+ APR_POLLSET_DEFAULT,
+ APR_POLLSET_SELECT,
+ APR_POLLSET_KQUEUE,
+ APR_POLLSET_PORT,
+ APR_POLLSET_EPOLL,
+ APR_POLLSET_POLL};
+
+ nsds = 1;
+ t1 = apr_time_now();
+ rv = apr_poll(NULL, 0, &nsds, apr_time_from_msec(200));
+ t2 = apr_time_now();
+ ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
+ ABTS_INT_EQUAL(tc, 0, nsds);
+ ABTS_ASSERT(tc,
+ "apr_poll() didn't sleep",
+ (t2 - t1) > apr_time_from_msec(100));
+
+ for (i = 0; i < sizeof methods / sizeof methods[0]; i++) {
+ rv = apr_pollset_create_ex(&pollset, 5, p, 0, methods[i]);
+ if (rv != APR_ENOTIMPL) {
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ nsds = 1;
+ t1 = apr_time_now();
+ rv = apr_pollset_poll(pollset, apr_time_from_msec(200), &nsds,
+ &hot_files);
+ t2 = apr_time_now();
+ ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
+ ABTS_INT_EQUAL(tc, 0, nsds);
+ ABTS_ASSERT(tc,
+ "apr_pollset_poll() didn't sleep",
+ (t2 - t1) > apr_time_from_msec(100));
+
+ rv = apr_pollset_destroy(pollset);
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+ }
+
+ rv = apr_pollcb_create_ex(&pollcb, 5, p, 0, methods[0]);
+ if (rv != APR_ENOTIMPL) {
+ ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+ t1 = apr_time_now();
+ rv = apr_pollcb_poll(pollcb, apr_time_from_msec(200), NULL, NULL);
+ t2 = apr_time_now();
+ ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv));
+ ABTS_ASSERT(tc,
+ "apr_pollcb_poll() didn't sleep",
+ (t2 - t1) > apr_time_from_msec(100));
+
+ /* no apr_pollcb_destroy() */
+ }
+ }
+}
+
abts_suite *testpoll(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -808,6 +871,7 @@ abts_suite *testpoll(abts_suite *suite)
abts_run_test(suite, close_all_sockets, NULL);
abts_run_test(suite, pollset_default, NULL);
abts_run_test(suite, pollcb_default, NULL);
+ abts_run_test(suite, justsleep, NULL);
return suite;
}