You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/05/19 19:27:40 UTC
svn commit: r1125009 -
/commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
Author: mturk
Date: Thu May 19 17:27:39 2011
New Revision: 1125009
URL: http://svn.apache.org/viewvc?rev=1125009&view=rev
Log:
Add direct Poll api
Modified:
commons/sandbox/runtime/trunk/src/main/native/os/unix/poll.c
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=1125009&r1=1125008&r2=1125009&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 Thu May 19 17:27:39 2011
@@ -80,7 +80,7 @@ static short reventt(short event)
}
-ACR_NET_EXPORT(jlong, Poll, create0)(JNI_STDARGS, jint size)
+ACR_NET_EXPORT(jlong, Pollset, create0)(JNI_STDARGS, jint size)
{
int rc;
acr_pollset_t *ps;
@@ -131,7 +131,7 @@ cleanup:
return 0;
}
-ACR_NET_EXPORT(void, Poll, destroy0)(JNI_STDARGS, jlong pollset)
+ACR_NET_EXPORT(void, Pollset, destroy0)(JNI_STDARGS, jlong pollset)
{
int i;
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -170,8 +170,8 @@ ACR_NET_EXPORT(void, Poll, destroy0)(JNI
AcrFree(ps);
}
-ACR_NET_EXPORT(jint, Poll, clear0)(JNI_STDARGS, jlong pollset,
- jobjectArray rs)
+ACR_NET_EXPORT(jint, Pollset, clear0)(JNI_STDARGS, jlong pollset,
+ jobjectArray rs)
{
int i;
int cnt = 0;
@@ -207,7 +207,7 @@ ACR_NET_EXPORT(jint, Poll, clear0)(JNI_S
return cnt;
}
-ACR_NET_EXPORT(void, Poll, wakeup0)(JNI_STDARGS, jlong pollset)
+ACR_NET_EXPORT(void, Pollset, wakeup0)(JNI_STDARGS, jlong pollset)
{
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -220,9 +220,9 @@ ACR_NET_EXPORT(void, Poll, wakeup0)(JNI_
pthread_mutex_unlock(&ps->mutex);
}
-ACR_NET_EXPORT(jint, Poll, wait0)(JNI_STDARGS, jlong pollset, jobjectArray rs,
- jshortArray revents, jint timeout,
- jboolean rmsignaled)
+ACR_NET_EXPORT(jint, Pollset, wait0)(JNI_STDARGS, jlong pollset, jobjectArray rs,
+ jshortArray revents, jint timeout,
+ jboolean rmsignaled)
{
int i, ns, rc = 0;
int rv = 0;
@@ -349,8 +349,8 @@ ACR_NET_EXPORT(jint, Poll, wait0)(JNI_ST
return rv;
}
-ACR_NET_EXPORT(jint, Poll, add0)(JNI_STDARGS, jlong pollset, jobject fo,
- jint f, jint events, jint ttlms)
+ACR_NET_EXPORT(jint, Pollset, add0)(JNI_STDARGS, jlong pollset, jobject fo,
+ jint f, jint events, jint ttlms)
{
int rc = 0;
acr_pollset_t *ps = J2P(pollset, acr_pollset_t *);
@@ -388,3 +388,99 @@ cleanup:
pthread_mutex_unlock(&ps->mutex);
return rc;
}
+
+ACR_UNX_EXPORT(jint, Poll, poll0)(JNI_STDARGS, jintArray fdset,
+ jshortArray events, jshortArray revents,
+ jint nevents, jint timeout)
+{
+ int ns, i;
+ struct pollfd pfds[1024];
+ struct pollfd *pfd;
+ jshort *pevents;
+ jint *pfdset;
+ acr_time_t tmx = 0;
+
+ if (nevents > 1024) {
+ pfd = ACR_MALLOC(struct pollfd, nevents);
+ if (pfd == 0)
+ return -1;
+ }
+ else
+ pfd = pfds;
+ pfdset = JARRAY_CRITICAL(jint, fdset);
+ pevents = JARRAY_CRITICAL(jshort, events);
+ for (i = 0; i < nevents; i++) {
+ pfd[i].fd = pfdset[i];
+ pfd[i].events = ieventt(pevents[i]);
+ pfd[i].revents = 0;
+ }
+ RELEASE_CRITICAL(events, pevents);
+ RELEASE_CRITICAL(fdset, pfdset);
+
+ if (timeout > 0)
+ tmx = AcrTimeMilliseconds() + timeout;
+ for (;;) {
+ ns = poll(pfd, nevents, timeout);
+ if (ns == -1 && errno == EINTR) {
+ if (timeout >= 0) {
+ timeout = tmx - AcrTimeMilliseconds();
+ if (timeout <= 0) {
+ ns = 0;
+ break;
+ }
+ }
+ }
+ else
+ break;
+ }
+
+ if (ns == -1) {
+ ACR_THROW_NET_ERRNO();
+ goto finally;
+ }
+ if (ns > 0) {
+ pevents = JARRAY_CRITICAL(jshort, revents);
+ for (i = 0; i < nevents; i++)
+ pevents[i] = reventt(pfd[i].revents);
+ RELEASE_CRITICAL(revents, pevents);
+ }
+
+finally:
+ if (pfd != pfds)
+ AcrFree(pfd);
+ return ns;
+}
+
+ACR_UNX_EXPORT(jint, Poll, poll1)(JNI_STDARGS, jint fd,
+ jshort events, jint timeout)
+{
+ int ns;
+ struct pollfd pfd;
+ acr_time_t tmx = 0;
+
+ pfd.fd = fd;
+ pfd.events = ieventt(events);
+ pfd.revents = 0;
+
+ if (timeout > 0)
+ tmx = AcrTimeMilliseconds() + timeout;
+ for (;;) {
+ ns = poll(&pfd, 1, timeout);
+ if (ns == -1 && errno == EINTR) {
+ if (timeout >= 0) {
+ timeout = tmx - AcrTimeMilliseconds();
+ if (timeout <= 0) {
+ ns = 0;
+ break;
+ }
+ }
+ }
+ else
+ break;
+ }
+ if (ns == -1)
+ return -1;
+ else
+ return reventt(pfd.revents);
+}
+
\ No newline at end of file