Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0CABA4257 for ; Sat, 25 Jun 2011 16:03:33 +0000 (UTC) Received: (qmail 79896 invoked by uid 500); 25 Jun 2011 16:03:32 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 79694 invoked by uid 500); 25 Jun 2011 16:03:31 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 79687 invoked by uid 99); 25 Jun 2011 16:03:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Jun 2011 16:03:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 25 Jun 2011 16:03:28 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 24AEE2388994 for ; Sat, 25 Jun 2011 16:03:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1139568 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.msc.in os/win32/poll.c shared/select.c Date: Sat, 25 Jun 2011 16:03:07 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110625160307.24AEE2388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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);