Author: mturk
Date: Sat Jun 25 16:03:06 2011
New Revision: 1139568
URL: http://svn.apache.org/viewvc?rev=1139568&view=rev
Log:
Add win32 poll
Added:
commons/sandbox/runtime/trunk/src/main/native/os/win32/poll.c (with props)
Modified:
commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
commons/sandbox/runtime/trunk/src/main/native/shared/select.c
Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=1139568&r1=1139567&r2=1139568&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Sat Jun 25
16:03:06 2011
@@ -75,7 +75,6 @@ ZLIB_SOURCES=\
ASMSOURCES=
WIN32_SOURCES=\
- $(TOPDIR)\os\win32\atomic.c \
$(TOPDIR)\os\win32\dirent.c \
$(TOPDIR)\os\win32\dso.c \
$(TOPDIR)\os\win32\exec.c \
@@ -85,6 +84,7 @@ WIN32_SOURCES=\
$(TOPDIR)\os\win32\os.c \
$(TOPDIR)\os\win32\path.c \
$(TOPDIR)\os\win32\platform.c \
+ $(TOPDIR)\os\win32\poll.c \
$(TOPDIR)\os\win32\posix.c \
$(TOPDIR)\os\win32\procmutex.c \
$(TOPDIR)\os\win32\registry.c \
Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/poll.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/poll.c?rev=1139568&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/poll.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/poll.c Sat Jun 25
16:03:06 2011
@@ -0,0 +1,165 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/netapi.h"
+#include "acr/memory.h"
+#include "acr/jniapi.h"
+#include "acr/port.h"
+#include "acr/time.h"
+#include "acr/iodefs.h"
+#include "acr/misc.h"
+#include "arch_opts.h"
+
+static short ieventt(int event)
+{
+ short rv = 0;
+
+ if (event & ACR_OP_INP)
+ rv |= POLLIN;
+ if (event & ACR_OP_OUT)
+ rv |= POLLOUT;
+ if (event & ACR_OP_PRI)
+ rv |= POLLPRI;
+ /* POLLERR, POLLHUP, and POLLNVAL aren't valid as requested events
+ */
+ return rv;
+}
+
+static short reventt(short event)
+{
+ short rv = 0;
+
+ if (event & POLLIN)
+ rv |= ACR_OP_INP;
+ if (event & POLLOUT)
+ rv |= ACR_OP_OUT;
+ if (event & POLLPRI)
+ rv |= ACR_OP_PRI;
+ if (event & POLLERR)
+ rv |= ACR_OP_ERROR;
+ if (event & POLLHUP)
+ rv |= ACR_OP_HANGUP;
+#if defined(POLLRDHUP)
+ if (event & POLLRDHUP)
+ rv |= ACR_OP_RDHUP;
+#endif
+ if (event & POLLNVAL)
+ rv |= ACR_OP_NVAL;
+ return rv;
+}
+
+ACR_NET_EXPORT(jint, Poll, wait0)(JNI_STDARGS, jlongArray fdset,
+ jshortArray events, jshortArray revents,
+ jint nevents, jint timeout)
+{
+ int ns, i;
+ struct pollfd pfds[1024];
+ struct pollfd *pfd;
+ jshort *pevents;
+ jlong *pfdset;
+ acr_time_t tmx = 0;
+
+ if (!ACR_HAVE_LATE_DLL_FUNC(WSAPoll)) {
+ ACR_THROW_NET_ERROR(ACR_ENOTIMPL);
+ return 0;
+ }
+ if (nevents > 1024) {
+ pfd = ACR_MALLOC(struct pollfd, nevents);
+ if (pfd == 0)
+ return 0;
+ }
+ else
+ pfd = pfds;
+ pfdset = JARRAY_CRITICAL(jlong, fdset);
+ pevents = JARRAY_CRITICAL(jshort, events);
+ for (i = 0; i < nevents; i++) {
+ pfd[i].fd = (J2P(pfdset[i], acr_fd_t *))->u.s;
+ 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 = WSAPoll(pfd, nevents, timeout);
+ if (ns == -1 && errno == EINTR) {
+ if (timeout > 0) {
+ timeout = (int)(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_NET_EXPORT(jshort, Poll, wait1)(JNI_STDARGS, jlong fp,
+ jshort events, jint timeout)
+{
+ int ns;
+ struct pollfd pfd;
+ acr_time_t tmx = 0;
+ acr_fd_t *fd = J2P(fp, acr_fd_t *);
+
+ if (!ACR_HAVE_LATE_DLL_FUNC(WSAPoll)) {
+ ACR_THROW_NET_ERROR(ACR_ENOTIMPL);
+ return 0;
+ }
+ pfd.fd = fd->u.s;
+ pfd.events = ieventt(events);
+ pfd.revents = 0;
+
+ if (timeout > 0)
+ tmx = AcrTimeMilliseconds() + timeout;
+ for (;;) {
+ ns = WSAPoll(&pfd, 1, timeout);
+ if (ns == -1 && errno == EINTR) {
+ if (timeout > 0) {
+ timeout = (int)(tmx - AcrTimeMilliseconds());
+ if (timeout <= 0) {
+ ns = 0;
+ break;
+ }
+ }
+ }
+ else
+ break;
+ }
+ if (ns == -1)
+ ACR_THROW_NET_ERRNO();
+ return reventt(pfd.revents);
+}
Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/poll.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/main/native/shared/select.c
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/select.c?rev=1139568&r1=1139567&r2=1139568&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/select.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/select.c Sat Jun 25
16:03:06 2011
@@ -53,15 +53,13 @@ ACR_NET_EXPORT(jint, Select, wait0)(JNI_
pevents = JARRAY_CRITICAL(jshort, events);
for (i = 0; i < nevents; i++) {
fd = J2P(pfdset[i], acr_fd_t *);
-#if defined(FD_SETSIZE)
-# if !defined(WINDOWS)
+#if defined(FD_SETSIZE) && !defined(WINDOWS)
if (fd->u.s > FD_SETSIZE) {
RELEASE_CRITICAL(events, pevents);
RELEASE_CRITICAL(fdset, pfdset);
ACR_THROW_NET_ERROR(ACR_ERANGE);
return 0;
}
-# endif
#endif
if (pevents[i] & ACR_OP_INP) {
FD_SET(fd->u.s, &rdset);
@@ -120,7 +118,7 @@ ACR_NET_EXPORT(jint, Select, wait0)(JNI_
pevents[i] = ACR_OP_ERROR | ACR_OP_NVAL;
ns++;
}
- }
+ }
}
RELEASE_CRITICAL(revents, pevents);
if (ns != 0) {
@@ -148,7 +146,7 @@ ACR_NET_EXPORT(jint, Select, wait0)(JNI_
}
}
RELEASE_CRITICAL(revents, pevents);
- RELEASE_CRITICAL(fdset, pfdset);
+ RELEASE_CRITICAL(fdset, pfdset);
return ns;
}
@@ -176,7 +174,7 @@ ACR_NET_EXPORT(jshort, Select, wait1)(JN
}
if (events & ~(ACR_OP_INP | ACR_OP_OUT)) {
FD_SET(fd->u.s, &exset);
- }
+ }
if (timeout >= 0) {
#if !defined(WINDOWS)
tmx = AcrTimeNow() + AcrTimeFromMsec(timeout);