Skip to content

Commit

Permalink
Fix a longstanding missunderstanding in our kqueue pollset code. It t…
Browse files Browse the repository at this point in the history
…urns

out that the kqueue filter types are not bitfields, so checking for them
via & EVFILT_READ or & EVFILT_WRITE is inappropriate.

Test Fixes By: Joe Orton

* poll/unix/kqueue.c
  (get_kqueue_revent): Use == instead of & when testing for filter types.

* test/testpoll.c
  (multi_event_pollset): Handle the fact that we can sometimes get multiple
   events for a single socket.

* CHANGES: Note fix.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@386154 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Garrett Rooney committed Mar 15, 2006
1 parent 4df9098 commit 847ad00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changes for APR 1.3.0

*) Correct bug in kqueue backend for apr_pollset where we would
erroneously indicate that a socket was readable or writeable.
[Garrett Rooney]

*) Implement support for apr_proc_mutex_trylock() on Unix platforms.
PR 38785. [Chris Darroch <chrisd pearsoncmg.com>]

Expand Down
4 changes: 2 additions & 2 deletions poll/unix/kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ static apr_int16_t get_kqueue_revent(apr_int16_t event, apr_int16_t flags)
{
apr_int16_t rv = 0;

if (event & EVFILT_READ)
if (event == EVFILT_READ)
rv |= APR_POLLIN;
if (event & EVFILT_WRITE)
if (event == EVFILT_WRITE)
rv |= APR_POLLOUT;
if (flags & EV_EOF)
rv |= APR_POLLHUP;
Expand Down
23 changes: 19 additions & 4 deletions test/testpoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,25 @@ static void multi_event_pollset(abts_case *tc, void *data)

rv = apr_pollset_poll(pollset, 0, &lrv, &descs);
ABTS_INT_EQUAL(tc, 0, APR_STATUS_IS_TIMEUP(rv));
ABTS_INT_EQUAL(tc, 1, lrv);
ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s);
ABTS_INT_EQUAL(tc, APR_POLLIN | APR_POLLOUT, descs[0].rtnevents);
ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data);
if (lrv == 1) {
ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s);
ABTS_INT_EQUAL(tc, APR_POLLIN | APR_POLLOUT, descs[0].rtnevents);
ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data);
}
else if (lrv == 2) {
ABTS_PTR_EQUAL(tc, s[0], descs[0].desc.s);
ABTS_PTR_EQUAL(tc, s[0], descs[0].client_data);
ABTS_PTR_EQUAL(tc, s[0], descs[1].desc.s);
ABTS_PTR_EQUAL(tc, s[0], descs[1].client_data);
ABTS_ASSERT(tc, "returned events incorrect",
((descs[0].rtnevents | descs[1].rtnevents)
== (APR_POLLIN | APR_POLLOUT))
&& descs[0].rtnevents != descs[1].rtnevents);
}
else {
ABTS_ASSERT(tc, "either one or two events returned",
lrv == 1 || lrv == 2);
}

recv_msg(s, 0, p, tc);

Expand Down

0 comments on commit 847ad00

Please sign in to comment.