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 7B96765EA for ; Fri, 15 Jul 2011 11:33:53 +0000 (UTC) Received: (qmail 55020 invoked by uid 500); 15 Jul 2011 11:33:50 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 54683 invoked by uid 500); 15 Jul 2011 11:33:48 -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 54676 invoked by uid 99); 15 Jul 2011 11:33:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Jul 2011 11:33:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FRT_STOCK2 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; Fri, 15 Jul 2011 11:33:39 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9F1E923889DA for ; Fri, 15 Jul 2011 11:33:17 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1147101 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/include/acr/ native/os/unix/ native/os/win32/ Date: Fri, 15 Jul 2011 11:33:17 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110715113317.9F1E923889DA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Fri Jul 15 11:33:16 2011 New Revision: 1147101 URL: http://svn.apache.org/viewvc?rev=1147101&view=rev Log: Axe LocalDescriptor and merge with SocketDescriptor Removed: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalDescriptor.java Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java?rev=1147101&r1=1147100&r2=1147101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalEndpoint.java Fri Jul 15 11:33:16 2011 @@ -42,7 +42,7 @@ import org.apache.commons.runtime.Timeou */ public class LocalEndpoint extends Connection { - private final LocalDescriptor sd; + private final SocketDescriptor sd; private EndpointAddress ea; private SelectionKeyImpl key; private boolean connected = false; @@ -55,7 +55,7 @@ public class LocalEndpoint extends Conne public LocalEndpoint() { super(EndpointType.LOCAL); - this.sd = new LocalDescriptor(); + this.sd = new SocketDescriptor(); } /** @@ -67,7 +67,7 @@ public class LocalEndpoint extends Conne super(EndpointType.LOCAL); if (sd == null || ea == null) throw new NullPointerException(); - this.sd = (LocalDescriptor)sd; + this.sd = (SocketDescriptor)sd; this.ea = ea; connected = true; } Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java?rev=1147101&r1=1147100&r2=1147101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/LocalServerEndpoint.java Fri Jul 15 11:33:16 2011 @@ -40,7 +40,7 @@ import org.apache.commons.runtime.Status public class LocalServerEndpoint extends ServerEndpoint { private static final int LISTEN_BACKLOG = 50; - private final LocalDescriptor sd; + private final SocketDescriptor sd; private SelectionKeyImpl key; private EndpointAddress sa; private boolean bound = false; @@ -54,14 +54,14 @@ public class LocalServerEndpoint extends public LocalServerEndpoint() { super(EndpointType.LOCAL); - this.sd = new LocalDescriptor(); + this.sd = new SocketDescriptor(); } /** * Creates a new local server endpoint from the * given socket descriptor. */ - public LocalServerEndpoint(LocalDescriptor sd) + public LocalServerEndpoint(SocketDescriptor sd) { super(EndpointType.LOCAL); if (sd == null) @@ -193,7 +193,7 @@ public class LocalServerEndpoint extends if (sd.closed()) throw new ClosedDescriptorException(); long fd = accept0(sd.fd(), sa.sockaddr(), blocking); - LocalDescriptor ad = new LocalDescriptor(fd); + SocketDescriptor ad = new SocketDescriptor(fd); return new LocalEndpoint(ad, sa); } Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java?rev=1147101&r1=1147100&r2=1147101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java (original) +++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketDescriptor.java Fri Jul 15 11:33:16 2011 @@ -37,10 +37,12 @@ final class SocketDescriptor extends Des private static native int sendz0(long fd); private static native long socket0(int af, int type, boolean blocking) throws IOException; + private static native long socket1(int type, boolean blocking) + throws IOException; private static native int block0(long fd, boolean block); private static native int tmset0(long fd, int timeout); private static native int shutdown0(long fd, int how); - private static native boolean isBlocking0(long fd) + private static native boolean blocking0(long fd) throws IOException; public SocketDescriptor() @@ -66,12 +68,25 @@ final class SocketDescriptor extends Des closed = false; } + public void create(SocketType type) + throws IOException + { + create(type, true); + } + + public void create(SocketType type, boolean blocking) + throws IOException + { + this.fd = socket1(type.valueOf(), blocking); + closed = false; + } + public boolean isBlocking() throws IOException { if (closed()) throw new ClosedDescriptorException(); - return isBlocking0(fd); + return blocking0(fd); } public SocketDescriptor configureBlocking(boolean block) Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h?rev=1147101&r1=1147100&r2=1147101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h Fri Jul 15 11:33:16 2011 @@ -29,9 +29,10 @@ * Descriptor types */ #define ACR_DT_FILE 0x0001 -#define ACR_DT_SOCKET 0x0002 -#define ACR_DT_LSOCK 0x0003 -#define ACR_DT_PIPE 0x0004 +#define ACR_DT_PIPE 0x0002 +#define ACR_DT_SOCKET 0x0003 +#define ACR_DT_LOCALSOCK 0x0004 +#define ACR_DT_SSLSOCK 0x0005 typedef struct acr_fd_t acr_fd_t; struct acr_fd_t { Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c?rev=1147101&r1=1147100&r2=1147101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/inetsock.c Fri Jul 15 11:33:16 2011 @@ -120,6 +120,70 @@ ACR_NET_EXPORT(jlong, SocketDescriptor, return P2J(sp); } +ACR_NET_EXPORT(jlong, SocketDescriptor, socket1)(JNI_STDARGS, jint stype, + jboolean block) +{ + int sd; + int rc = 0; + int type = 0; + + acr_sd_t *sp; + + switch (stype) { + case 1: + type = SOCK_STREAM; + break; + case 2: + type = SOCK_DGRAM; + break; + case 3: + type = SOCK_RAW; + break; + + } +#if HAVE_SOCK_NONBLOCK + if (block == JNI_FALSE) + type |= SOCK_NONBLOCK; +#endif +#if HAVE_SOCK_CLOEXEC + type |= SOCK_CLOEXEC; +#endif + sd = socket(AF_LOCAL, type, 0); + if (sd == -1) + rc = errno; +#if !HAVE_SOCK_CLOEXEC + rc = AcrCloseOnExec(sd, 1); + if (rc != 0) + r_close(sd); +#endif +#if !HAVE_SOCK_NONBLOCK + if (block == JNI_FALSE && rc == 0) { + rc = AcrNonblock(sd, 1); + if (rc != 0) + r_close(sd); + } +#endif + if (rc != 0) { + ACR_THROW_NET_ERROR(rc); + return 0; + } + if ((sp = ACR_TALLOC(acr_sd_t)) == 0) { + r_close(sd); + return 0; + } + sp->type = ACR_DT_LOCALSOCK; + sp->refs = 1; + sp->s = sd; + if (block == JNI_FALSE) { + sp->flags = ACR_DT_NONBLOCK; + sp->timeout = 0; + } + else { + sp->timeout = -1; + } + return P2J(sp); +} + ACR_NET_EXPORT(jint, SocketDescriptor, close0)(JNI_STDARGS, jlong fp) { int sd, rc = 0; @@ -181,16 +245,14 @@ ACR_NET_EXPORT(jint, SocketDescriptor, b if (on == JNI_TRUE) { if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK) && (rc = AcrNonblock(fd->s, 0)) == 0) { - fd->timeout = -1; #if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO - { - int zero = 0; - setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - } + int zero = 0; + setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, + (char *)&zero, (socklen_t)sizeof(zero)); + setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, + (char *)&zero, (socklen_t)sizeof(zero)); #endif + fd->timeout = -1; ACR_CLRFLAG(fd, ACR_DT_NONBLOCK); } } @@ -204,7 +266,7 @@ ACR_NET_EXPORT(jint, SocketDescriptor, b return rc; } -ACR_NET_EXPORT(jboolean, SocketDescriptor, isBlocking0)(JNI_STDARGS, jlong fp) +ACR_NET_EXPORT(jboolean, SocketDescriptor, blocking0)(JNI_STDARGS, jlong fp) { acr_sd_t *fd = J2P(fp, acr_sd_t *); @@ -214,6 +276,53 @@ ACR_NET_EXPORT(jboolean, SocketDescripto return JNI_TRUE; } +ACR_NET_EXPORT(jint, SocketDescriptor, tmset0)(JNI_STDARGS, jlong fp, jint timeout) +{ + int rc; + acr_sd_t *fd = J2P(fp, acr_sd_t *); + + if (timeout == 0) { + if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { + if ((rc = AcrNonblock(fd->s, 1)) != 0) + return rc; + ACR_SETFLAG(fd, ACR_DT_NONBLOCK); + } + } + else if (timeout > 0) { + if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { + if ((rc = AcrNonblock(fd->s, 1)) != 0) + return rc; + ACR_SETFLAG(fd, ACR_DT_NONBLOCK); + } +#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO + if (fd->timeout != timeout) { + setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, + (char *)&timeout, (socklen_t)sizeof(timeout)); + setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, + (char *)&timeout, (socklen_t)sizeof(timeout)); + } +#endif + } + else if (timeout < 0) { + if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { + if ((rc = AcrNonblock(fd->s, 0)) != 0) + return rc; + ACR_CLRFLAG(fd, ACR_DT_NONBLOCK); + } +#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO + { + int zero = 0; + setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, + (char *)&zero, (socklen_t)sizeof(zero)); + setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, + (char *)&zero, (socklen_t)sizeof(zero)); + } +#endif + } + fd->timeout = timeout; + return 0; +} + ACR_NET_EXPORT(jboolean, SocketAddress, haveipv6)(JNI_STDARGS) { int sock; Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c?rev=1147101&r1=1147100&r2=1147101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c Fri Jul 15 11:33:16 2011 @@ -55,209 +55,6 @@ ACR_INLINE(int) release_sd(acr_sd_t *sd) return 1; } -ACR_NET_EXPORT(jint, LocalDescriptor, close0)(JNI_STDARGS, jlong fp) -{ - int sd, rc = 0; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (fd == 0) - return ACR_EBADF; - sd = fd->s; - if (sd != -1) { - fd->s = -1; - if (r_close(sd) == -1) - rc = ACR_GET_OS_ERROR(); - } - if (AcrAtomic32Dec(&fd->refs) == 0) - AcrFree(fd); - return rc; -} - -ACR_NET_EXPORT(jint, LocalDescriptor, shutdown0)(JNI_STDARGS, jlong fp, - jint how) -{ - int rc = 0; - int sd; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (fd == 0) - return ACR_EBADF; - if (how == 0) - how = SHUT_RD; - else if (how == 1) - how = SHUT_WR; - else - how = SHUT_RDWR; - sd = retain_sd(fd); - if (shutdown(sd, how) == -1) - rc = ACR_GET_NETOS_ERROR(); - if (how != 1) { - ACR_SETFLAG(fd, ACR_DT_HITEOF); - } - release_sd(fd); - return rc; -} - -ACR_NET_EXPORT(jint, LocalDescriptor, sendz0)(JNI_STDARGS, jlong fp) -{ - char dummy = 0; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (r_write(fd->s, &dummy, 0) == -1) - return ACR_GET_OS_ERROR(); - else - return 0; -} - -ACR_NET_EXPORT(jlong, LocalDescriptor, socket0)(JNI_STDARGS, jint stype, - jboolean block) -{ - int sd; - int rc = 0; - int type = 0; - - acr_sd_t *sp; - - switch (stype) { - case 1: - type = SOCK_STREAM; - break; - case 2: - type = SOCK_DGRAM; - break; - case 3: - type = SOCK_RAW; - break; - - } -#if HAVE_SOCK_NONBLOCK - if (block == JNI_FALSE) - type |= SOCK_NONBLOCK; -#endif -#if HAVE_SOCK_CLOEXEC - type |= SOCK_CLOEXEC; -#endif - sd = socket(AF_LOCAL, type, 0); - if (sd == -1) - rc = errno; -#if !HAVE_SOCK_CLOEXEC - rc = AcrCloseOnExec(sd, 1); - if (rc != 0) - r_close(sd); -#endif -#if !HAVE_SOCK_NONBLOCK - if (block == JNI_FALSE && rc == 0) { - rc = AcrNonblock(sd, 1); - if (rc != 0) - r_close(sd); - } -#endif - if (rc != 0) { - ACR_THROW_NET_ERROR(rc); - return 0; - } - if ((sp = ACR_TALLOC(acr_sd_t)) == 0) { - r_close(sd); - return 0; - } - sp->type = ACR_DT_LSOCK; - sp->refs = 1; - sp->s = sd; - if (block == JNI_FALSE) { - sp->flags = ACR_DT_NONBLOCK; - sp->timeout = 0; - } - else { - sp->timeout = -1; - } - return P2J(sp); -} - -ACR_NET_EXPORT(jint, LocalDescriptor, block0)(JNI_STDARGS, jlong fp, jboolean on) -{ - int rc = 0; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (on == JNI_TRUE) { - if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK) && (rc = AcrNonblock(fd->s, 0)) == 0) { -#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO - int zero = 0; - setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); -#endif - fd->timeout = -1; - ACR_CLRFLAG(fd, ACR_DT_NONBLOCK); - } - } - else { - if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK) && (rc = AcrNonblock(fd->s, 1)) == 0) { - if (fd->timeout < 0) - fd->timeout = 0; - ACR_SETFLAG(fd, ACR_DT_NONBLOCK); - } - } - return rc; -} - -ACR_NET_EXPORT(jint, LocalDescriptor, tmset0)(JNI_STDARGS, jlong fp, jint timeout) -{ - int rc; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (timeout == 0) { - if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { - if ((rc = AcrNonblock(fd->s, 1)) != 0) - return rc; - ACR_SETFLAG(fd, ACR_DT_NONBLOCK); - } - } - else if (timeout > 0) { - if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { - if ((rc = AcrNonblock(fd->s, 1)) != 0) - return rc; - ACR_SETFLAG(fd, ACR_DT_NONBLOCK); - } -#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO - if (fd->timeout != timeout) { - setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, - (char *)&timeout, (socklen_t)sizeof(timeout)); - setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, - (char *)&timeout, (socklen_t)sizeof(timeout)); - } -#endif - } - else if (timeout < 0) { - if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { - if ((rc = AcrNonblock(fd->s, 0)) != 0) - return rc; - ACR_CLRFLAG(fd, ACR_DT_NONBLOCK); - } -#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO - { - int zero = 0; - setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - } -#endif - } - fd->timeout = timeout; - return 0; -} - -ACR_NET_EXPORT(jboolean, LocalDescriptor, blocking0)(JNI_STDARGS, jlong fp) -{ - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) - return JNI_FALSE; - else - return JNI_TRUE; -} - ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jlong fp, jbyteArray cb, jint timeout) { @@ -414,7 +211,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin r_close(sd); return 0; } - sp->type = ACR_DT_LSOCK; + sp->type = ACR_DT_LOCALSOCK; sp->flags = fd->flags; sp->timeout = fd->timeout; sp->refs = 1; Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c?rev=1147101&r1=1147100&r2=1147101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c Fri Jul 15 11:33:16 2011 @@ -79,6 +79,11 @@ ACR_NET_EXPORT(jint, SocketDescriptor, c } if (sd != INVALID_SOCKET) { fd->s = INVALID_SOCKET; + if (fd->socketfname != 0) { + DeleteFileW(fd->socketfname); + AcrFree(fd->socketfname); + fd->socketfname = 0; + } if (closesocket(sd) == SOCKET_ERROR) rc = ACR_GET_NETOS_ERROR(); fd->s = INVALID_SOCKET; @@ -106,8 +111,9 @@ ACR_NET_EXPORT(jint, SocketDescriptor, s sd = retain_sd(fd); if (shutdown(fd->s, how) == SOCKET_ERROR) rc = ACR_GET_NETOS_ERROR(); - if (how != 1) - fd->flags |= ACR_DT_HITEOF; + if (how != 1) { + ACR_SETFLAG(fd, ACR_DT_HITEOF); + } release_sd(fd); return rc; } @@ -153,14 +159,14 @@ ACR_NET_EXPORT(jint, SocketDescriptor, b return 0; } -ACR_NET_EXPORT(jboolean, SocketDescriptor, isBlocking0)(JNI_STDARGS, jlong fp) +ACR_NET_EXPORT(jboolean, SocketDescriptor, blocking0)(JNI_STDARGS, jlong fp) { acr_sd_t *fd = J2P(fp, acr_sd_t *); - if ((fd->flags & ACR_DT_NONBLOCK) == 0) - return JNI_TRUE; - else + if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) return JNI_FALSE; + else + return JNI_TRUE; } ACR_NET_EXPORT(jint, SocketDescriptor, tmset0)(JNI_STDARGS, jlong fp, jint timeout) @@ -169,17 +175,17 @@ ACR_NET_EXPORT(jint, SocketDescriptor, t acr_sd_t *fd = J2P(fp, acr_sd_t *); if (timeout == 0) { - if ((fd->flags & ACR_DT_NONBLOCK) == 0) { + if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { if ((rc = AcrNonblock(fd->s, 1)) != 0) return rc; - fd->flags |= ACR_DT_NONBLOCK; + ACR_SETFLAG(fd, ACR_DT_NONBLOCK); } } else if (timeout > 0) { - if ((fd->flags & ACR_DT_NONBLOCK) == 0) { + if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { if ((rc = AcrNonblock(fd->s, 1)) != 0) return rc; - fd->flags |= ACR_DT_NONBLOCK; + ACR_SETFLAG(fd, ACR_DT_NONBLOCK); } if (fd->timeout != timeout) { setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, @@ -190,10 +196,10 @@ ACR_NET_EXPORT(jint, SocketDescriptor, t } else if (timeout < 0) { int zero = 0; - if ((fd->flags & ACR_DT_NONBLOCK) != 0) { + if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { if ((rc = AcrNonblock(fd->s, 0)) != 0) return rc; - fd->flags &= ~ACR_DT_NONBLOCK; + ACR_CLRFLAG(fd, ACR_DT_NONBLOCK); } setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, (char *)&zero, (socklen_t)sizeof(zero)); @@ -203,3 +209,116 @@ ACR_NET_EXPORT(jint, SocketDescriptor, t fd->timeout = timeout; return 0; } + +ACR_NET_EXPORT(jlong, SocketDescriptor, socket0)(JNI_STDARGS, jint saf, + jint stype, jboolean block) +{ + int rc = 0; + int af = AF_UNSPEC; + int type = 0; + SCOCKET sd; + acr_sd_t *sp; + + switch (stype) { + case 1: + type = SOCK_STREAM; + break; + case 2: + type = SOCK_DGRAM; + break; + case 3: + type = SOCK_RAW; + break; + } + switch (saf) { + case 1: + af = AF_INET; + break; + case 2: + af = AF_INET6; + break; + case 3: + af = AF_LOCAL; + break; + } + sd = socket(af, type, 0); + if (sd == INVALID_SOCKET) + rc = ACR_GET_NETOS_ERROR(); + if (block == JNI_FALSE && rc == 0) { + u_long one = 1; + if (ioctlsocket(sd, FIONBIO, &one) == SOCKET_ERROR) { + rc = ACR_GET_NETOS_ERROR(); + closesocket(sd); + } + } + if (rc != 0) { + ACR_THROW_NET_ERROR(rc); + return 0; + } + if ((sp = ACR_TALLOC(acr_sd_t)) == 0) { + closesocket(sd); + return 0; + } + sp->type = ACR_DT_SOCKET; + sp->refs = 1; + sp->s = sd; + if (block == JNI_FALSE) { + sp->flags = ACR_DT_NONBLOCK; + sp->timeout = 0; + } + else { + sp->timeout = -1; + } + return P2J(sp); +} + +ACR_NET_EXPORT(jlong, SocketDescriptor, socket1)(JNI_STDARGS, jint stype, + jboolean block) +{ + SOCKET sd; + int rc = 0; + int type = 0; + acr_sd_t *sp; + + switch (stype) { + case 1: + type = SOCK_STREAM; + break; + case 2: + type = SOCK_DGRAM; + break; + case 3: + type = SOCK_RAW; + break; + + } + sd = socket(AF_INET, type, 0); + if (sd == INVALID_SOCKET) + rc = ACR_GET_NETOS_ERROR(); + if (block == JNI_FALSE && rc == 0) { + u_long one = 1; + if (ioctlsocket(sd, FIONBIO, &one) == SOCKET_ERROR) { + rc = ACR_GET_NETOS_ERROR(); + closesocket(sd); + } + } + if (rc != 0) { + ACR_THROW_NET_ERROR(rc); + return 0; + } + if ((sp = ACR_TALLOC(acr_sd_t)) == 0) { + closesocket(sd); + return 0; + } + sp->type = ACR_DT_LOCALSOCK; + sp->refs = 1; + sp->s = sd; + if (block == JNI_FALSE) { + ACR_SETFLAG(sp, ACR_DT_NONBLOCK); + sp->timeout = 0; + } + else { + sp->timeout = -1; + } + return P2J(sp); +} Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c?rev=1147101&r1=1147100&r2=1147101&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c Fri Jul 15 11:33:16 2011 @@ -62,205 +62,6 @@ ACR_INLINE(int) release_sd(acr_sd_t *sd) return 1; } -ACR_NET_EXPORT(jint, LocalDescriptor, close0)(JNI_STDARGS, jlong fp) -{ - int rc = 0; - SOCKET sd; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (fd == 0) - return ACR_EBADF; - sd = fd->s; - if (fd->pob != 0) { - /* Close TransmitFile overlapped struct */ - SAFE_CLOSE_HANDLE(fd->pob->hEvent); - AcrFree(fd->pob); - fd->pob = 0; - } - if (sd != INVALID_SOCKET) { - fd->s = INVALID_SOCKET; - if (fd->socketfname != 0) { - DeleteFileW(fd->socketfname); - AcrFree(fd->socketfname); - fd->socketfname = 0; - } - if (closesocket(sd) == SOCKET_ERROR) - rc = ACR_GET_NETOS_ERROR(); - fd->s = INVALID_SOCKET; - } - if (AcrAtomic32Dec(&fd->refs) == 0) - AcrFree(fd); - return rc; -} - -ACR_NET_EXPORT(jint, LocalDescriptor, shutdown0)(JNI_STDARGS, jlong fp, - jint how) -{ - int rc = 0; - SOCKET sd; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (fd == 0) - return ACR_EBADF; - if (how == 0) - how = SD_RECEIVE; - else if (how == 1) - how = SD_SEND; - else - how = SD_BOTH; - sd = retain_sd(fd); - if (shutdown(fd->s, how) == SOCKET_ERROR) - rc = ACR_GET_NETOS_ERROR(); - if (how != 1) { - ACR_SETFLAG(fd, ACR_DT_HITEOF); - } - release_sd(fd); - return rc; -} - -ACR_NET_EXPORT(jint, LocalDescriptor, sendz0)(JNI_STDARGS, jlong fp) -{ - char dummy = 0; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (send(fd->s, &dummy, 0, 0) == SOCKET_ERROR) - return ACR_GET_NETOS_ERROR(); - else - return 0; -} - -ACR_NET_EXPORT(jlong, LocalDescriptor, socket0)(JNI_STDARGS, jint stype, - jboolean block) -{ - SOCKET sd; - int rc = 0; - int type = 0; - acr_sd_t *sp; - - switch (stype) { - case 1: - type = SOCK_STREAM; - break; - case 2: - type = SOCK_DGRAM; - break; - case 3: - type = SOCK_RAW; - break; - - } - sd = socket(AF_INET, type, 0); - if (sd == INVALID_SOCKET) - rc = ACR_GET_NETOS_ERROR(); - if (block == JNI_FALSE && rc == 0) { - u_long one = 1; - if (ioctlsocket(sd, FIONBIO, &one) == SOCKET_ERROR) { - rc = ACR_GET_NETOS_ERROR(); - closesocket(sd); - } - } - if (rc != 0) { - ACR_THROW_NET_ERROR(rc); - return 0; - } - if ((sp = ACR_TALLOC(acr_sd_t)) == 0) { - closesocket(sd); - return 0; - } - sp->type = ACR_DT_LSOCK; - sp->refs = 1; - sp->s = sd; - if (block == JNI_FALSE) { - ACR_SETFLAG(sp, ACR_DT_NONBLOCK); - sp->timeout = 0; - } - else { - sp->timeout = -1; - } - return P2J(sp); -} - -ACR_NET_EXPORT(jint, LocalDescriptor, block0)(JNI_STDARGS, jlong fp, jboolean on) -{ - int rc; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (on == JNI_TRUE) { - if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { - int zero = 0; - if ((rc = AcrNonblock(fd->s, 0)) != 0) - return rc; - setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - fd->timeout = -1; - ACR_CLRFLAG(fd, ACR_DT_NONBLOCK); - } - } - else { - if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { - if ((rc = AcrNonblock(fd->s, 1)) != 0) - return rc; - if (fd->timeout < 0) - fd->timeout = 0; - ACR_SETFLAG(fd, ACR_DT_NONBLOCK); - } - } - return 0; -} - -ACR_NET_EXPORT(jboolean, LocalDescriptor, blocking0)(JNI_STDARGS, jlong fp) -{ - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) - return JNI_FALSE; - else - return JNI_TRUE; -} - -ACR_NET_EXPORT(jint, LocalDescriptor, tmset0)(JNI_STDARGS, jlong fp, jint timeout) -{ - int rc = 0; - acr_sd_t *fd = J2P(fp, acr_sd_t *); - - if (timeout == 0) { - if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { - if ((rc = AcrNonblock(fd->s, 1)) != 0) - return rc; - ACR_SETFLAG(fd, ACR_DT_NONBLOCK); - } - } - else if (timeout > 0) { - if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { - if ((rc = AcrNonblock(fd->s, 1)) != 0) - return rc; - ACR_SETFLAG(fd, ACR_DT_NONBLOCK); - } - if (fd->timeout != timeout) { - setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, - (char *)&timeout, (socklen_t)sizeof(timeout)); - setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, - (char *)&timeout, (socklen_t)sizeof(timeout)); - } - } - else if (timeout < 0) { - int zero = 0; - if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) { - if ((rc = AcrNonblock(fd->s, 0)) != 0) - return rc; - ACR_CLRFLAG(fd, ACR_DT_NONBLOCK); - } - setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO, - (char *)&zero, (socklen_t)sizeof(zero)); - } - fd->timeout = timeout; - return 0; -} - ACR_NET_EXPORT(jint, LocalEndpoint, connect0)(JNI_STDARGS, jlong fp, jbyteArray cb, jint timeout) { @@ -467,7 +268,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin } SOCKADDR_RELEASE(ba, aa); - sp->type = ACR_DT_LSOCK; + sp->type = ACR_DT_LOCALSOCK; sp->flags = fd->flags; sp->timeout = fd->timeout; sp->refs = 1;