commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1147273 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/ native/include/acr/ native/os/unix/ native/os/win32/
Date Fri, 15 Jul 2011 18:36:21 GMT
Author: mturk
Date: Fri Jul 15 18:36:17 2011
New Revision: 1147273

URL: http://svn.apache.org/viewvc?rev=1147273&view=rev
Log:
Split setting soket options to a separate file

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h
    commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.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/unix/sockstream.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/inetsock.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java?rev=1147273&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java
Fri Jul 15 18:36:17 2011
@@ -0,0 +1,101 @@
+/* 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.
+ */
+
+package org.apache.commons.runtime.net;
+
+/** Represents the Socket option type.
+ */
+public enum SocketOption
+{
+    /**
+     * Invalid option.
+     */
+    INVALID(            0),
+    /**
+     * Enables transimission and receipt of the broadcast messages
+     * on the socket.
+     */
+    BROADCAST(          1),
+    /**
+     * Don't accept IPv4 connections on an IPv6 listening socket.
+     */
+    IPV6_V6ONLY(        2),
+    /**
+     * Sends keep-alives.
+     */
+    KEEPALIVE(          3),
+    /** Specifies the linger-on-close timeout.
+     */
+    LINGER(             4),
+    /**
+     * Non-blocking IO.
+     */
+    NONBLOCK(           5),
+    /**
+     * Specifies the total per-socket buffer space reserved for receives.
+     */
+    RCVBUF(             6),
+    /**
+     * Specifies the total per-socket buffer space reserved for send.
+     */
+    SNDBUF(             7),
+    /**
+     * Allows the socket to be bound to an address that is already in use.
+     */
+    REUSEADDR(          8),
+    /**
+     * Sets timeout on blocking socket operations.
+     */
+    TIMEOUT(            9),
+    /**
+     * Delay accepting of new connections until data is available.
+     */
+    TCP_DEFER_ACCEPT(  10),
+    /**
+     * Disables the Nagle algorithm for send cealescing.
+     */
+    TCP_NODELAY(       11),
+    /**
+     * No push.
+     */
+    TCP_NOPUSH(        12);
+
+    private int value;
+    private SocketOption(int v)
+    {
+        value = v;
+    }
+
+    public int valueOf()
+    {
+        return value;
+    }
+
+    public boolean isLocal()
+    {
+        return value > 1;
+    }
+
+    public static SocketOption valueOf(int value)
+    {
+        for (SocketOption e : values()) {
+            if (e.value == value)
+                return e;
+        }
+        return INVALID;
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1147273&r1=1147272&r2=1147273&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Fri Jul 15 18:36:17 2011
@@ -94,6 +94,7 @@ WIN32_SOURCES=\
 	$(TOPDIR)\os\win32\selectset.c \
 	$(TOPDIR)\os\win32\semaphore.c \
 	$(TOPDIR)\os\win32\shmem.c \
+	$(TOPDIR)\os\win32\sockopts.c \
 	$(TOPDIR)\os\win32\sockstream.c \
 	$(TOPDIR)\os\win32\time.c \
 	$(TOPDIR)\os\win32\util.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1147273&r1=1147272&r2=1147273&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Fri Jul 15 18:36:17 2011
@@ -74,6 +74,7 @@ UNIX_SOURCES=\
 	$(TOPDIR)/os/unix/shmem.c \
 	$(TOPDIR)/os/unix/selectset.c \
 	$(TOPDIR)/os/unix/semaphore.c \
+	$(TOPDIR)/os/unix/sockopts.c \
 	$(TOPDIR)/os/unix/sockstream.c \
 	$(TOPDIR)/os/unix/time.c \
 	$(TOPDIR)/os/unix/util.c

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=1147273&r1=1147272&r2=1147273&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 18:36:17
2011
@@ -20,19 +20,28 @@
 #include "acr/jniapi.h"
 
 /**
- * Descriptor flags
+ * Socket flags
  */
-#define ACR_DT_NONBLOCK     0x0001
-#define ACR_DT_HITEOF       0x0002
+#define ACR_SO_RDEOF            0x0001
+
+#define ACR_SO_NONBLOCK         0x0010
+#define ACR_SO_BROADCAST        0x0020
+#define ACR_SO_IPV6_V6ONLY      0x0040
+#define ACR_SO_KEEPALIVE        0x0080
+#define ACR_SO_LINGER           0x0100
+#define ACR_SO_REUSEADDR        0x0200
+#define ACR_TCP_DEFER_ACCEPT    0x0400
+#define ACR_TCP_NODELAY         0x0800
+#define ACR_TCP_NOPUSH          0x1000
 
 /**
  * Descriptor types
  */
-#define ACR_DT_FILE         0x0001
-#define ACR_DT_PIPE         0x0002
-#define ACR_DT_SOCKET       0x0003
-#define ACR_DT_LOCALSOCK    0x0004
-#define ACR_DT_SSLSOCK      0x0005
+#define ACR_DT_FILE             0x0001
+#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/include/acr/netdefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h?rev=1147273&r1=1147272&r2=1147273&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h Fri Jul 15 18:36:17
2011
@@ -67,5 +67,21 @@
 #define ACR_PS_TYPE_WINDOWS        3
 #define ACR_PS_TYPE_WINPIPE        4
 
+/** Socket options.
+ * NOTICE: Make sure they are in sync with
+ *         the SocketOption.java enum
+ */
+#define ACR_OPT_SO_BROADCAST          1
+#define ACR_OPT_SO_IPV6_V6ONLY        2
+#define ACR_OPT_SO_KEEPALIVE          3
+#define ACR_OPT_SO_LINGER             4
+#define ACR_OPT_SO_NONBLOCK           5
+#define ACR_OPT_SO_RCVBUF             6
+#define ACR_OPT_SO_SNDBUF             7
+#define ACR_OPT_SO_REUSEADDR          8
+#define ACR_OPT_SO_TIMEOUT            9
+#define ACR_OPT_SO_TCP_DEFER_ACCEPT  10
+#define ACR_OPT_SO_TCP_NODELAY       11
+#define ACR_OPT_SO_TCP_NOPUSH        12
 
 #endif /* _ACR_IODEFS_H */

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h?rev=1147273&r1=1147272&r2=1147273&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/stddefs.h Fri Jul 15 18:36:17
2011
@@ -300,9 +300,11 @@
 #define ACR_NOT(o, f)           (((o) & (f)) == 0)
 #define ACR_ISSET(o, f)         (((o) & (f)) == (f))
 
-#define ACR_SETFLAG(o, f)       do { (o)->flags |=  (f); } while (0)
-#define ACR_CLRFLAG(o, f)       do { (o)->flags &= ~(f); } while (0)
-#define ACR_HASFLAG(o, f)       (((o)->flags & (f)) != 0)
+#define ACR_SETFLAG(s, f)       do { (s)->flags |=  (f); } while (0)
+#define ACR_CLRFLAG(s, f)       do { (s)->flags &= ~(f); } while (0)
+#define ACR_HASFLAG(s, f)       (((s)->flags & (f)) != 0)
+#define ACR_PUTFLAG(s, f, on)   do { if (on) (s)->flags |= (f); \
+                                else (s)->flags &= ~(f); } while (0)
 
 #define UNUSED_SOURCE_FILE(F)   \
 const char __provided_##F [] = "Using system provided " #F "()"

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=1147273&r1=1147272&r2=1147273&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 18:36:17 2011
@@ -90,7 +90,7 @@ ACR_NET_EXPORT(jlong, SocketDescriptor, 
     sp->refs    = 1;
     sp->s       = sd;
     if (block == JNI_FALSE) {
-        sp->flags   = ACR_DT_NONBLOCK;
+        sp->flags   = ACR_SO_NONBLOCK;
         sp->timeout = 0;
     }
     else {
@@ -154,7 +154,7 @@ ACR_NET_EXPORT(jlong, SocketDescriptor, 
     sp->refs    = 1;
     sp->s       = sd;
     if (block == JNI_FALSE) {
-        sp->flags   = ACR_DT_NONBLOCK;
+        sp->flags   = ACR_SO_NONBLOCK;
         sp->timeout = 0;
     }
     else {
@@ -211,7 +211,7 @@ ACR_NET_EXPORT(jint, SocketDescriptor, s
     if (shutdown(fd->s, how) == -1)
         rc = ACR_GET_NETOS_ERROR();
     if (how != 1) {
-        ACR_SETFLAG(fd, ACR_DT_HITEOF);
+        ACR_SETFLAG(fd, ACR_SO_RDEOF);
     }
     AcrSdRelease(fd);
     return rc;
@@ -223,7 +223,7 @@ ACR_NET_EXPORT(jint, SocketDescriptor, b
     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 (ACR_HASFLAG(fd, ACR_SO_NONBLOCK) && (rc = AcrNonblock(fd->s, 0)) ==
0) {
 #if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO
             int zero = 0;
             setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
@@ -232,14 +232,14 @@ ACR_NET_EXPORT(jint, SocketDescriptor, b
                         (char *)&zero, (socklen_t)sizeof(zero));
 #endif
             fd->timeout = -1;
-            ACR_CLRFLAG(fd, ACR_DT_NONBLOCK);
+            ACR_CLRFLAG(fd, ACR_SO_NONBLOCK);
         }
     }
     else {
-        if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK) && (rc = AcrNonblock(fd->s, 1))
== 0) {
+        if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK) && (rc = AcrNonblock(fd->s, 1))
== 0) {
             if (fd->timeout < 0)
                 fd->timeout = 0;
-            ACR_SETFLAG(fd, ACR_DT_NONBLOCK);
+            ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
         }
     }
     return rc;
@@ -249,68 +249,8 @@ ACR_NET_EXPORT(jboolean, SocketDescripto
 {
     acr_sd_t *fd = J2P(fp, acr_sd_t *);
 
-    if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK))
+    if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK))
         return JNI_FALSE;
     else
         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;
-
-    sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
-    if (sock != -1) {
-        close(sock);
-        return JNI_TRUE;
-    }
-    else
-        return JNI_FALSE;
-}

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=1147273&r1=1147272&r2=1147273&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 18:36:17
2011
@@ -45,7 +45,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
     sd = AcrSdRetain(fd);
     if (timeout == 0)
         timeout = fd->timeout;
-    if (timeout > 0 && !ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
+    if (timeout > 0 && !ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
         /* Turn the socket to non-blocking mode
          */
         if ((rc = AcrNonblock(sd, 1)) != 0)
@@ -74,7 +74,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
                 }
 #endif
             }
-            if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK))
+            if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK))
                  AcrNonblock(fd->s, 0);
         }
     }
@@ -159,7 +159,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
     if (block == JNI_FALSE) {
         int rc = 0;
 #if HAVE_NONBLOCK_INHERITED
-        if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK))
+        if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK))
 #endif
         rc = AcrNonblock(sd, 1);
         if (rc != 0) {
@@ -169,7 +169,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
         }
     }
 #if HAVE_NONBLOCK_INHERITED
-    else if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
+    else if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
         /* We have nonblocking acceptor and need
          * blocking socket
          */
@@ -196,12 +196,12 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
     sp->refs    = 1;
     sp->s       = sd;
     if (block == JNI_FALSE) {
-        ACR_SETFLAG(sp, ACR_DT_NONBLOCK);
+        ACR_SETFLAG(sp, ACR_SO_NONBLOCK);
         if (sp->timeout < 0)
             sp->timeout = 0;
     }
     else {
-        ACR_CLRFLAG(sp, ACR_DT_NONBLOCK);
+        ACR_CLRFLAG(sp, ACR_SO_NONBLOCK);
     }
     return P2J(sp);
 }

Added: commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c?rev=1147273&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c Fri Jul 15 18:36:17 2011
@@ -0,0 +1,184 @@
+/* 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/error.h"
+#include "acr/iodefs.h"
+#include "acr/clazz.h"
+#include "acr/string.h"
+#include "acr/memory.h"
+#include "acr/iofd.h"
+#include "acr/netapi.h"
+#include "acr/unsafe.h"
+#include "acr/port.h"
+#include "acr/time.h"
+#include "arch_opts.h"
+#include "arch_sync.h"
+#if HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#include <poll.h>
+
+#define SOCKADDR_CAST(BA) \
+    (acr_sockaddr_t *)AcrGetArrayCritical(env, (BA))
+#define SOCKADDR_RELEASE(BA, SA) \
+    AcrReleaseArrayCritical(env, (BA), (SA))
+#define SSIZEOF(s) (socklen_t)sizeof(s)
+
+ACR_NET_EXPORT(jboolean, SocketAddress, haveipv6)(JNI_STDARGS)
+{
+    int sock;
+
+    sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
+    if (sock != -1) {
+        close(sock);
+        return JNI_TRUE;
+    }
+    else
+        return JNI_FALSE;
+}
+
+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_SO_NONBLOCK)) {
+            if ((rc = AcrNonblock(fd->s, 1)) != 0)
+                return rc;
+            ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
+        }
+    }
+    else if (timeout > 0) {
+        if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+            if ((rc = AcrNonblock(fd->s, 1)) != 0)
+                return rc;
+            ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
+        }
+#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO
+        if (fd->timeout != timeout) {
+            setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
+                      (char *)&timeout, SSIZEOF(timeout));
+            setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
+                      (char *)&timeout, SSIZEOF(timeout));
+        }
+#endif
+    }
+    else if (timeout < 0) {
+        if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+            if ((rc = AcrNonblock(fd->s, 0)) != 0)
+                return rc;
+            ACR_CLRFLAG(fd, ACR_SO_NONBLOCK);
+        }
+#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO
+        {
+            int zero = 0;
+            setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
+                      (char *)&zero, SSIZEOF(zero));
+            setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
+                      (char *)&zero, SSIZEOF(zero));
+        }
+#endif
+    }
+    fd->timeout = timeout;
+    return 0;
+}
+
+ACR_NET_EXPORT(jint, SocketDescriptor, optset0)(JNI_STDARGS, jlong fp,
+                                                jint opt, jint val)
+{
+    int rc = 0;
+    acr_sd_t *fd = J2P(fp, acr_sd_t *);
+
+    /* Set numeric values */
+    switch (opt) {
+        case ACR_OPT_SO_SNDBUF:
+#if defined(SO_SNDBUF)
+            if (setsockopt(fd->s, SOL_SOCKET, SO_SNDBUF, (void *)&opt, SSIZEOF(int))
!= 0)
+                return ACR_GET_NETOS_ERROR();
+#else
+            rc = ACR_ENOTIMPL;
+#endif
+        break;
+        case ACR_OPT_SO_RCVBUF:
+#if defined(SO_RCVBUF)
+            if (setsockopt(fd->s, SOL_SOCKET, SO_RCVBUF, (void *)&opt, SSIZEOF(int))
!= 0)
+                return ACR_GET_NETOS_ERROR();
+#else
+            rc = ACR_ENOTIMPL;
+#endif
+        break;
+        case ACR_OPT_SO_LINGER:
+#ifdef SO_LINGER
+        {
+            struct linger li;
+            li.l_onoff  = opt == 0 ? 0 : 1;
+            li.l_linger = opt;
+            if (setsockopt(fd->s, SOL_SOCKET, SO_LINGER, (char *)&li, SSIZEOF(struct
linger)) != 0)
+                return ACR_GET_NETOS_ERROR();
+            ACR_PUTFLAG(fd, ACR_SO_LINGER, opt);
+        }
+#else
+            rc = ACR_ENOTIMPL;
+#endif
+        break;
+        case ACR_OPT_SO_TIMEOUT:
+            if (val == 0) {
+                if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+                    if ((rc = AcrNonblock(fd->s, 1)) != 0)
+                        return rc;
+                    ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
+                }
+            }
+            else if (val > 0) {
+                if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+                    if ((rc = AcrNonblock(fd->s, 1)) != 0)
+                        return rc;
+                    ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
+                }
+#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO
+                if (fd->timeout != val) {
+                    setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
+                            (char *)&val, SSIZEOF(int));
+                    setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
+                            (char *)&val, SSIZEOF(int));
+                }
+#endif
+            }
+            else if (val < 0) {
+                if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+                    if ((rc = AcrNonblock(fd->s, 0)) != 0)
+                        return rc;
+                    ACR_CLRFLAG(fd, ACR_SO_NONBLOCK);
+                }
+#if HAVE_SO_RCVTIMEO && HAVE_SO_SNDTIMEO
+                {
+                    int zero = 0;
+                    setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
+                            (char *)&zero, SSIZEOF(int));
+                    setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
+                            (char *)&zero, SSIZEOF(int));
+                }
+#endif
+            }
+            fd->timeout = val;
+        break;
+        default:
+            rc = ACR_EINVAL;
+        break;
+    }
+    return rc;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c?rev=1147273&r1=1147272&r2=1147273&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sockstream.c Fri Jul 15 18:36:17
2011
@@ -87,7 +87,7 @@ ACR_NET_EXPORT(jint, SocketStream, close
 ACR_NET_EXPORT(jboolean, SocketStream, eof0)(JNI_STDARGS, jlong sp)
 {
     acr_ss_t *ss = J2P(sp, acr_ss_t *);
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         return JNI_TRUE;
     else
         return JNI_FALSE;
@@ -103,7 +103,7 @@ ACR_NET_EXPORT(jboolean, SocketStream, e
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     rc = AcrWaitIO(sd, 0, POLLIN);
     if (rc == 0) {
@@ -119,7 +119,7 @@ ACR_NET_EXPORT(jboolean, SocketStream, e
         rc = 0;
     }
     if (rv) {
-        ACR_SETFLAG(ss->fd, ACR_DT_HITEOF);
+        ACR_SETFLAG(ss->fd, ACR_SO_RDEOF);
     }
 finally:
     sdrelease(ss);
@@ -158,7 +158,7 @@ ACR_NET_EXPORT(jint, SocketStream, read0
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     rd = r_read(sd, &ch, 1);
     if (rd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) &&
@@ -173,7 +173,7 @@ ACR_NET_EXPORT(jint, SocketStream, read0
     else if (rd == 1)
         rv = ch;
     else
-        ss->fd->flags |= ACR_DT_HITEOF;
+        ss->fd->flags |= ACR_SO_RDEOF;
 finally:
     sdrelease(ss);
     if (rc != 0) {
@@ -200,7 +200,7 @@ ACR_NET_EXPORT(jint, SocketStream, read1
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     if (len > ACR_PBUFF_SIZ) {
         if (len > ACR_MEGABYTE) {
@@ -227,7 +227,7 @@ ACR_NET_EXPORT(jint, SocketStream, read1
     if (rd == -1)
         rc = ACR_GET_NETOS_ERROR();
     else if (rd == 0)
-        ss->fd->flags |= ACR_DT_HITEOF;
+        ss->fd->flags |= ACR_SO_RDEOF;
 
 finally:
     sdrelease(ss);
@@ -271,7 +271,7 @@ ACR_NET_EXPORT(jint, SocketStream, read2
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     if (bb == 0) {
         rc = ACR_EINVAL;
@@ -288,7 +288,7 @@ ACR_NET_EXPORT(jint, SocketStream, read2
     if (rd == -1)
         rc = ACR_GET_NETOS_ERROR();
     else if (rd == 0)
-        ss->fd->flags |= ACR_DT_HITEOF;
+        ss->fd->flags |= ACR_SO_RDEOF;
 
 finally:
     sdrelease(ss);
@@ -315,7 +315,7 @@ ACR_NET_EXPORT(jint, SocketStream, read3
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     bb = (char *)(*env)->GetDirectBufferAddress(env, buf);
     if (bb == 0) {
@@ -334,7 +334,7 @@ ACR_NET_EXPORT(jint, SocketStream, read3
     if (rd == -1)
         rc = ACR_GET_NETOS_ERROR();
     else if (rd == 0)
-        ss->fd->flags |= ACR_DT_HITEOF;
+        ss->fd->flags |= ACR_SO_RDEOF;
 
 finally:
     sdrelease(ss);

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=1147273&r1=1147272&r2=1147273&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 18:36:17
2011
@@ -91,7 +91,7 @@ ACR_NET_EXPORT(jint, SocketDescriptor, s
     if (shutdown(sd, how) == SOCKET_ERROR)
         rc = ACR_GET_NETOS_ERROR();
     if (how != 1) {
-        ACR_SETFLAG(fd, ACR_DT_HITEOF);
+        ACR_SETFLAG(fd, ACR_SO_RDEOF);
     }
     AcrSdRelease(fd);
     return rc;
@@ -114,7 +114,7 @@ ACR_NET_EXPORT(jint, SocketDescriptor, b
     acr_sd_t *fd = J2P(fp, acr_sd_t *);
 
     if (on == JNI_TRUE) {
-        if ((fd->flags & ACR_DT_NONBLOCK) != 0) {
+        if ((fd->flags & ACR_SO_NONBLOCK) != 0) {
             int zero = 0;
             if ((rc = AcrNonblock(fd->s, 0)) != 0)
                 return rc;
@@ -123,16 +123,16 @@ ACR_NET_EXPORT(jint, SocketDescriptor, b
             setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
                         (char *)&zero, (socklen_t)sizeof(zero));
             fd->timeout = -1;
-            fd->flags &= ~ACR_DT_NONBLOCK;
+            fd->flags &= ~ACR_SO_NONBLOCK;
         }
     }
     else {
-        if ((fd->flags & ACR_DT_NONBLOCK) == 0) {
+        if ((fd->flags & ACR_SO_NONBLOCK) == 0) {
             if ((rc = AcrNonblock(fd->s, 1)) != 0)
                 return rc;
             if (fd->timeout < 0)
                 fd->timeout = 0;
-            fd->flags |= ACR_DT_NONBLOCK;
+            fd->flags |= ACR_SO_NONBLOCK;
         }
     }    
     return 0;
@@ -142,7 +142,7 @@ ACR_NET_EXPORT(jboolean, SocketDescripto
 {
     acr_sd_t *fd = J2P(fp, acr_sd_t *);
 
-    if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK))
+    if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK))
         return JNI_FALSE;
     else
         return JNI_TRUE;
@@ -154,17 +154,17 @@ ACR_NET_EXPORT(jint, SocketDescriptor, t
     acr_sd_t *fd = J2P(fp, acr_sd_t *);
 
     if (timeout == 0) {
-        if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
+        if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
             if ((rc = AcrNonblock(fd->s, 1)) != 0)
                 return rc;
-            ACR_SETFLAG(fd, ACR_DT_NONBLOCK);
+            ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
         }
     }
     else if (timeout > 0) {
-        if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
+        if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
             if ((rc = AcrNonblock(fd->s, 1)) != 0)
                 return rc;
-            ACR_SETFLAG(fd, ACR_DT_NONBLOCK);
+            ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
         }
         if (fd->timeout != timeout) {
             setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
@@ -175,10 +175,10 @@ ACR_NET_EXPORT(jint, SocketDescriptor, t
     }
     else if (timeout < 0) {
         int zero = 0;
-        if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
+        if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
             if ((rc = AcrNonblock(fd->s, 0)) != 0)
                 return rc;
-            ACR_CLRFLAG(fd, ACR_DT_NONBLOCK);
+            ACR_CLRFLAG(fd, ACR_SO_NONBLOCK);
         }
         setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
                     (char *)&zero, (socklen_t)sizeof(zero));
@@ -242,7 +242,7 @@ ACR_NET_EXPORT(jlong, SocketDescriptor, 
     sp->refs    = 1;
     sp->s       = sd;
     if (block == JNI_FALSE) {
-        sp->flags   = ACR_DT_NONBLOCK;
+        sp->flags   = ACR_SO_NONBLOCK;
         sp->timeout = 0;
     }
     else {
@@ -293,7 +293,7 @@ ACR_NET_EXPORT(jlong, SocketDescriptor, 
     sp->refs    = 1;
     sp->s       = sd;
     if (block == JNI_FALSE) {
-        ACR_SETFLAG(sp, ACR_DT_NONBLOCK);
+        ACR_SETFLAG(sp, ACR_SO_NONBLOCK);
         sp->timeout = 0;
     }
     else {

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=1147273&r1=1147272&r2=1147273&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 18:36:17
2011
@@ -84,7 +84,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
     if (timeout == 0)
         timeout = fd->timeout;
     sd = AcrSdRetain(fd);
-    if (timeout > 0 && !ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
+    if (timeout > 0 && !ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
         /* Turn the socket to non-blocking mode
          * for the duration of the connect call.
          */
@@ -107,7 +107,7 @@ ACR_NET_EXPORT(jint, LocalEndpoint, conn
                         rc = err;
                 }
             }
-            if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK))
+            if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK))
                  AcrNonblock(sd, 0);
         }
     }
@@ -218,7 +218,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
         return 0;
     }
     if (block == JNI_FALSE) {
-        if (!ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
+        if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
             int rc = AcrNonblock(sd, 1);
             if (rc != 0) {
                 closesocket(sd);
@@ -227,7 +227,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
             }
         }
     }
-    else if (ACR_HASFLAG(fd, ACR_DT_NONBLOCK)) {
+    else if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
         int rc = AcrNonblock(sd, 0);
         if (rc != 0) {
             closesocket(sd);
@@ -253,12 +253,12 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
     sp->refs    = 1;
     sp->s       = sd;
     if (block == JNI_FALSE) {
-        ACR_SETFLAG(sp, ACR_DT_NONBLOCK);
+        ACR_SETFLAG(sp, ACR_SO_NONBLOCK);
         if (sp->timeout < 0)
             sp->timeout = 0;
     }
     else {
-        ACR_CLRFLAG(sp, ACR_DT_NONBLOCK);
+        ACR_CLRFLAG(sp, ACR_SO_NONBLOCK);
     }
     return P2J(sp);
 }

Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c?rev=1147273&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c Fri Jul 15 18:36:17
2011
@@ -0,0 +1,154 @@
+/* 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/jnitypes.h"
+#include "acr/error.h"
+#include "acr/memory.h"
+#include "acr/netapi.h"
+#include "acr/unsafe.h"
+#include "acr/port.h"
+#include "arch_opts.h"
+#include "arch_sync.h"
+
+#define SOCKADDR_CAST(BA) \
+    (acr_sockaddr_t *)AcrGetArrayCritical(env, (BA))
+#define SOCKADDR_RELEASE(BA, SA) \
+    AcrReleaseArrayCritical(env, (BA), (SA))
+#define SSIZEOF(s) (int)sizeof(s)
+
+ACR_NET_EXPORT(jboolean, SocketAddress, haveipv6)(JNI_STDARGS)
+{
+    SOCKET sock;
+
+    sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
+    if (sock != INVALID_SOCKET) {
+        closesocket(sock);
+        return JNI_TRUE;
+    }
+    else
+        return JNI_FALSE;
+}
+
+ACR_NET_EXPORT(jint, SocketDescriptor, 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_SO_NONBLOCK)) {
+            if ((rc = AcrNonblock(fd->s, 1)) != 0)
+                return rc;
+            ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
+        }
+    }
+    else if (timeout > 0) {
+        if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+            if ((rc = AcrNonblock(fd->s, 1)) != 0)
+                return rc;
+            ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
+        }
+        if (fd->timeout != timeout) {
+            setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
+                      (char *)&timeout, SSIZEOF(timeout));
+            setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
+                      (char *)&timeout, SSIZEOF(timeout));
+        }
+    }
+    else if (timeout < 0) {
+        int zero = 0;
+        if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+            if ((rc = AcrNonblock(fd->s, 0)) != 0)
+                return rc;
+            ACR_CLRFLAG(fd, ACR_SO_NONBLOCK);
+        }
+        setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
+                    (char *)&zero, SSIZEOF(zero));
+        setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
+                    (char *)&zero, SSIZEOF(zero));
+    }
+    fd->timeout = timeout;
+    return 0;
+}
+
+ACR_NET_EXPORT(jint, SocketDescriptor, optset0)(JNI_STDARGS, jlong fp,
+                                                jint opt, jint val)
+{
+    int rc = 0;
+    acr_sd_t *fd = J2P(fp, acr_sd_t *);
+
+    /* Set numeric values */
+    switch (opt) {
+        case ACR_OPT_SO_SNDBUF:
+            if (setsockopt(fd->s, SOL_SOCKET, SO_SNDBUF, (void *)&opt, SSIZEOF(int))
!= 0)
+                return ACR_GET_NETOS_ERROR();
+        break;
+        case ACR_OPT_SO_RCVBUF:
+            if (setsockopt(fd->s, SOL_SOCKET, SO_RCVBUF, (void *)&opt, SSIZEOF(int))
!= 0)
+                return ACR_GET_NETOS_ERROR();
+        break;
+        case ACR_OPT_SO_LINGER:
+        {
+            struct linger li;
+            li.l_onoff  = opt == 0 ? 0 : 1;
+            li.l_linger = opt;
+            if (setsockopt(fd->s, SOL_SOCKET, SO_LINGER, (char *)&li, SSIZEOF(struct
linger)) != 0)
+                return ACR_GET_NETOS_ERROR();
+            ACR_PUTFLAG(fd, ACR_SO_LINGER, opt);
+        }
+        break;
+        case ACR_OPT_SO_TIMEOUT:
+            if (val == 0) {
+                if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+                    if ((rc = AcrNonblock(fd->s, 1)) != 0)
+                        return rc;
+                    ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
+                }
+            }
+            else if (val > 0) {
+                if (!ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+                    if ((rc = AcrNonblock(fd->s, 1)) != 0)
+                        return rc;
+                    ACR_SETFLAG(fd, ACR_SO_NONBLOCK);
+                }
+                if (fd->timeout != val) {
+                    setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
+                            (char *)&val, SSIZEOF(int));
+                    setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
+                            (char *)&val, SSIZEOF(int));
+                }
+            }
+            else if (val < 0) {
+                if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+                    if ((rc = AcrNonblock(fd->s, 0)) != 0)
+                        return rc;
+                    ACR_CLRFLAG(fd, ACR_SO_NONBLOCK);
+                }
+                {
+                    int zero = 0;
+                    setsockopt(fd->s, SOL_SOCKET, SO_RCVTIMEO,
+                            (char *)&zero, SSIZEOF(int));
+                    setsockopt(fd->s, SOL_SOCKET, SO_SNDTIMEO,
+                            (char *)&zero, SSIZEOF(int));
+                }
+            }
+            fd->timeout = val;
+        break;
+        default:
+            rc = ACR_EINVAL;
+        break;
+    }
+    return rc;
+}

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c?rev=1147273&r1=1147272&r2=1147273&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sockstream.c Fri Jul 15 18:36:17
2011
@@ -83,7 +83,7 @@ ACR_NET_EXPORT(jint, SocketStream, close
 ACR_NET_EXPORT(jboolean, SocketStream, eof0)(JNI_STDARGS, jlong sp)
 {
     acr_ss_t *ss = J2P(sp, acr_ss_t *);
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         return JNI_TRUE;
     else
         return JNI_FALSE;
@@ -100,7 +100,7 @@ ACR_NET_EXPORT(jboolean, SocketStream, e
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     rc = AcrWaitIO(sd, 0, POLLIN);
     if (rc == 0) {
@@ -116,7 +116,7 @@ ACR_NET_EXPORT(jboolean, SocketStream, e
         rc = 0;
     }
     if (rv) {
-        ACR_SETFLAG(ss->fd, ACR_DT_HITEOF);
+        ACR_SETFLAG(ss->fd, ACR_SO_RDEOF);
     }
 finally:
     sdrelease(ss);
@@ -150,7 +150,7 @@ ACR_NET_EXPORT(jint, SocketStream, read0
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     rd = recv(sd, &ch, 1, 0);
     if (rd == SOCKET_ERROR && (WSAGetLastError() == WSAEWOULDBLOCK) &&
@@ -165,7 +165,7 @@ ACR_NET_EXPORT(jint, SocketStream, read0
     else if (rd == 1)
         rv = ch;
     else
-        ss->fd->flags |= ACR_DT_HITEOF;
+        ss->fd->flags |= ACR_SO_RDEOF;
 finally:
     sdrelease(ss);
     if (rc != 0) {
@@ -192,7 +192,7 @@ ACR_NET_EXPORT(jint, SocketStream, read1
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     if (len > ACR_PBUFF_SIZ) {
         if (len > ACR_MEGABYTE) {
@@ -219,7 +219,7 @@ ACR_NET_EXPORT(jint, SocketStream, read1
     if (rd == SOCKET_ERROR)
         rc = ACR_GET_OS_ERROR();
     else if (rd == 0)
-        ss->fd->flags |= ACR_DT_HITEOF;
+        ss->fd->flags |= ACR_SO_RDEOF;
 
 finally:
     sdrelease(ss);
@@ -263,7 +263,7 @@ ACR_NET_EXPORT(jint, SocketStream, read2
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     if (bb == 0) {
         rc = ACR_EINVAL;
@@ -280,7 +280,7 @@ ACR_NET_EXPORT(jint, SocketStream, read2
     if (rd == SOCKET_ERROR)
         rc = ACR_GET_NETOS_ERROR();
     else if (rd == 0)
-        ss->fd->flags |= ACR_DT_HITEOF;
+        ss->fd->flags |= ACR_SO_RDEOF;
 
 finally:
     sdrelease(ss);
@@ -307,7 +307,7 @@ ACR_NET_EXPORT(jint, SocketStream, read3
         rc = ACR_EBADF;
         goto finally;
     }
-    if (ACR_HASFLAG(ss->fd, ACR_DT_HITEOF))
+    if (ACR_HASFLAG(ss->fd, ACR_SO_RDEOF))
         goto finally;
     bb = (char *)(*env)->GetDirectBufferAddress(env, buf);
     if (bb == 0) {
@@ -326,7 +326,7 @@ ACR_NET_EXPORT(jint, SocketStream, read3
     if (rd == SOCKET_ERROR)
         rc = ACR_GET_NETOS_ERROR();
     else if (rd == 0)
-        ss->fd->flags |= ACR_DT_HITEOF;
+        ss->fd->flags |= ACR_SO_RDEOF;
 
 finally:
     sdrelease(ss);



Mime
View raw message