Author: mturk
Date: Wed May 18 04:59:38 2011
New Revision: 1104689
URL: http://svn.apache.org/viewvc?rev=1104689&view=rev
Log:
Use absolute time for poll
Modified:
commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h?rev=1104689&r1=1104688&r2=1104689&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/time.h Wed May 18
04:59:38 2011
@@ -35,7 +35,7 @@
/** @return acr_time_t msec portion of a time */
#define AcrTimeMsec(time) (((time) / 1000) % 1000)
/** @return milliseconds as an acr_time_t */
-#define AcrTimeFromMsec(msec) ((acr_time_t)(msec) * 1000)
+#define AcrTimeFromMsec(msc) ((acr_time_t)(msc) * ACR_MSEC_PER_SEC)
/** @return seconds as an acr_time_t */
#define AcrTimeFromSec(sec) ((acr_time_t)(sec) * ACR_USEC_PER_SEC)
/** @return a second and usec combination as an acr_time_t */
Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c?rev=1104689&r1=1104688&r2=1104689&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c Wed May 18
04:59:38 2011
@@ -131,7 +131,7 @@ cleanup:
return 0;
}
-ACR_NET_EXPORT(void, Poll, free0)(JNI_STDARGS, jlong pollset)
+ACR_NET_EXPORT(void, Poll, destroy0)(JNI_STDARGS, jlong pollset)
{
int i;
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -228,6 +228,7 @@ ACR_NET_EXPORT(jint, Poll, wait0)(JNI_ST
int rv = 0;
jshort *pevents;
acr_time_t now = 0;
+ acr_time_t tmx = 0;
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
pthread_mutex_lock(&ps->mutex);
@@ -249,9 +250,22 @@ ACR_NET_EXPORT(jint, Poll, wait0)(JNI_ST
ps->state = PSS_POLL;
pthread_mutex_unlock(&ps->mutex);
- do {
+ if (timeout > 0)
+ tmx = AcrTimeMilliseconds() + timeout;
+ for (;;) {
ns = poll(ps->fdset, ps->used, timeout);
- } while (ns == -1 && errno == EINTR);
+ if (ns == -1 && errno == EINTR) {
+ if (timeout >= 0) {
+ timeout = tmx - AcrTimeMilliseconds();
+ if (timeout <= 0) {
+ ns = 0;
+ break;
+ }
+ }
+ }
+ else
+ break;
+ }
if (ns == -1)
rc = ACR_GET_OS_ERROR();