Author: mturk
Date: Sat Jul 16 06:06:42 2011
New Revision: 1147363
URL: http://svn.apache.org/viewvc?rev=1147363&view=rev
Log:
Implement socket and tcp options ... most of them
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/TcpOption.java
(with props)
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/java/org/apache/commons/runtime/net/SocketEndpoint.java
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java
commons/sandbox/runtime/trunk/src/main/native/include/acr/netdefs.h
commons/sandbox/runtime/trunk/src/main/native/os/unix/localsock.c
commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/localsock.c
commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
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=1147363&r1=1147362&r2=1147363&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
Sat Jul 16 06:06:42 2011
@@ -106,7 +106,7 @@ public class LocalEndpoint extends Conne
public boolean isBlocking()
throws IOException
{
- return sd.isBlocking();
+ return sd.hasOption(SocketOption.NONBLOCK) == false;
}
@Override
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=1147363&r1=1147362&r2=1147363&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
Sat Jul 16 06:06:42 2011
@@ -202,10 +202,7 @@ public class LocalServerEndpoint extends
throws IOException
{
sd.setTimeout(timeout);
- if (timeout < 0)
- blocking = true;
- else
- blocking = false;
+ blocking = sd.hasOption(SocketOption.NONBLOCK) == false;
}
@Override
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=1147363&r1=1147362&r2=1147363&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
Sat Jul 16 06:06:42 2011
@@ -40,10 +40,12 @@ final class SocketDescriptor extends Des
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 blocking0(long fd)
+ private static native boolean optget0(long fd, int opt)
throws IOException;
+ private static native int optset0(long fd, int opt, int val);
+ private static native int optset1(long fd, int opt, boolean val);
+ private static native int optset2(long fd, int opt, boolean val);
+ private static native int shutdown0(long fd, int how);
public SocketDescriptor()
{
@@ -81,14 +83,6 @@ final class SocketDescriptor extends Des
closed = false;
}
- public boolean isBlocking()
- throws IOException
- {
- if (closed())
- throw new ClosedDescriptorException();
- return blocking0(fd);
- }
-
public SocketDescriptor configureBlocking(boolean block)
throws IOException
{
@@ -138,7 +132,7 @@ final class SocketDescriptor extends Des
{
if (closed())
throw new ClosedDescriptorException();
- int rc = tmset0(fd, timeout);
+ int rc = optset0(fd, 9 /* SocketOption.TIMEOUT.valueOf() */, timeout);
if (rc != 0)
throw new SocketException(Status.describe(rc));
}
@@ -153,4 +147,50 @@ final class SocketDescriptor extends Des
throw new SocketException(Status.describe(rc));
}
+ public void setOption(SocketOption key, int val)
+ throws IOException
+ {
+ if (closed())
+ throw new ClosedDescriptorException();
+ int rc = optset0(fd, key.valueOf(), val);
+ if (rc != 0)
+ throw new SocketException(Status.describe(rc));
+ }
+
+ public void setOption(SocketOption key, boolean val)
+ throws IOException
+ {
+ if (closed())
+ throw new ClosedDescriptorException();
+ int rc = optset1(fd, key.valueOf(), val);
+ if (rc != 0)
+ throw new SocketException(Status.describe(rc));
+ }
+
+ public void setOption(TcpOption key, boolean val)
+ throws IOException
+ {
+ if (closed())
+ throw new ClosedDescriptorException();
+ int rc = optset2(fd, key.valueOf(), val);
+ if (rc != 0)
+ throw new SocketException(Status.describe(rc));
+ }
+
+ public boolean hasOption(SocketOption key)
+ throws IOException
+ {
+ if (closed())
+ throw new ClosedDescriptorException();
+ return optget0(fd, key.valueOf());
+ }
+
+ public boolean hasOption(TcpOption key)
+ throws IOException
+ {
+ if (closed())
+ throw new ClosedDescriptorException();
+ return optget0(fd, key.valueOf());
+ }
+
}
Modified:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java?rev=1147363&r1=1147362&r2=1147363&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketEndpoint.java
Sat Jul 16 06:06:42 2011
@@ -90,7 +90,7 @@ public class SocketEndpoint extends Conn
public boolean isBlocking()
throws IOException
{
- return sd.isBlocking();
+ return sd.hasOption(SocketOption.NONBLOCK) == false;
}
@Override
@@ -205,4 +205,36 @@ public class SocketEndpoint extends Conn
return connected;
}
+ public boolean hasOption(SocketOption key)
+ throws IOException
+ {
+ return sd.hasOption(key);
+ }
+
+ public boolean hasOption(TcpOption key)
+ throws IOException
+ {
+ if (closed())
+ throw new ClosedDescriptorException();
+ return sd.hasOption(key);
+ }
+
+ public void setOption(SocketOption key, int val)
+ throws IOException
+ {
+ sd.setOption(key, val);
+ }
+
+ public void setOption(SocketOption key, boolean val)
+ throws IOException
+ {
+ sd.setOption(key, val);
+ }
+
+ public void setOption(TcpOption key, boolean val)
+ throws IOException
+ {
+ sd.setOption(key, val);
+ }
+
}
Modified:
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=1147363&r1=1147362&r2=1147363&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketOption.java
Sat Jul 16 06:06:42 2011
@@ -59,19 +59,7 @@ public enum SocketOption
/**
* 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);
+ TIMEOUT( 9);
private int value;
private SocketOption(int v)
@@ -84,11 +72,6 @@ public enum SocketOption
return value;
}
- public boolean isLocal()
- {
- return value > 1;
- }
-
public static SocketOption valueOf(int value)
{
for (SocketOption e : values()) {
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/TcpOption.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/TcpOption.java?rev=1147363&view=auto
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/TcpOption.java
(added)
+++
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/TcpOption.java
Sat Jul 16 06:06:42 2011
@@ -0,0 +1,60 @@
+/* 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 Tcp socket option type.
+ */
+public enum TcpOption
+{
+ /**
+ * Invalid option.
+ */
+ INVALID( 0),
+ /**
+ * Delay accepting of new connections until data is available.
+ */
+ DEFER_ACCEPT( 21),
+ /**
+ * Disables the Nagle algorithm for send cealescing.
+ */
+ NODELAY( 22),
+ /**
+ * No push.
+ */
+ TCP_NOPUSH( 23);
+
+ private int value;
+ private TcpOption(int v)
+ {
+ value = v;
+ }
+
+ public int valueOf()
+ {
+ return value;
+ }
+
+ public static TcpOption valueOf(int value)
+ {
+ for (TcpOption e : values()) {
+ if (e.value == value)
+ return e;
+ }
+ return INVALID;
+ }
+
+}
Propchange:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/TcpOption.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1147363&r1=1147362&r2=1147363&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 Sat Jul
16 06:06:42 2011
@@ -71,17 +71,22 @@
* 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
+#define ACR_OPT_SO_BROADCAST 1
+#define ACR_OPT_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
+
+/** Socket options.
+ * NOTICE: Make sure they are in sync with
+ * the TcpOption.java enum
+ */
+#define ACR_OPT_TCP_DEFER_ACCEPT 21
+#define ACR_OPT_TCP_NODELAY 22
+#define ACR_OPT_TCP_NOPUSH 23
#endif /* _ACR_IODEFS_H */
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=1147363&r1=1147362&r2=1147363&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 Sat Jul
16 06:06:42 2011
@@ -191,8 +191,11 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
return 0;
}
sp->type = ACR_DT_LOCALSOCK;
- sp->flags = fd->flags;
+#if HAVE_NONBLOCK_INHERITED
+ /* Inherit nonblocking flag */
+ sp->flags = fd->flags & ACR_SO_NONBLOCK;
sp->timeout = fd->timeout;
+#endif
sp->refs = 1;
sp->s = sd;
if (block == JNI_FALSE) {
@@ -202,6 +205,8 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
}
else {
ACR_CLRFLAG(sp, ACR_SO_NONBLOCK);
+ if (sp->timeout == 0)
+ sp->timeout = -1;
}
return P2J(sp);
}
Modified: 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=1147363&r1=1147362&r2=1147363&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/sockopts.c Sat Jul 16
06:06:42 2011
@@ -30,6 +30,8 @@
#include <sys/ioctl.h>
#endif
#include <poll.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
#define SOCKADDR_CAST(BA) \
(acr_sockaddr_t *)AcrGetArrayCritical(env, (BA))
@@ -50,53 +52,6 @@ ACR_NET_EXPORT(jboolean, SocketAddress,
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)
{
@@ -159,6 +114,7 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
#endif
}
else if (val < 0) {
+ val = -1;
if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
if ((rc = AcrNonblock(fd->s, 0)) != 0)
return rc;
@@ -182,3 +138,159 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
}
return rc;
}
+
+ACR_NET_EXPORT(jint, SocketDescriptor, optset1)(JNI_STDARGS, jlong fp,
+ jint opt, jboolean val)
+{
+ int rc = 0;
+ int on = val == JNI_TRUE ? 1 : 0;
+ acr_sd_t *fd = J2P(fp, acr_sd_t *);
+
+ /* Set numeric values */
+ switch (opt) {
+ case ACR_OPT_SO_KEEPALIVE:
+#if defined(SO_KEEPALIVE)
+ if (on != ACR_HASFLAG(fd, ACR_SO_KEEPALIVE)) {
+ if (setsockopt(fd->s, SOL_SOCKET, SO_KEEPALIVE, (void *)&on,
SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_SO_KEEPALIVE, on);
+ }
+#else
+ rc = ACR_ENOTIMPL;
+#endif
+ break;
+ case ACR_OPT_SO_REUSEADDR:
+ if (on != ACR_HASFLAG(fd, ACR_SO_REUSEADDR)) {
+ if (setsockopt(fd->s, SOL_SOCKET, SO_REUSEADDR, (void *)&on,
SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_SO_REUSEADDR, on);
+ }
+ break;
+ case ACR_OPT_SO_NONBLOCK:
+ if (on != ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+ if ((rc = AcrNonblock(fd->s, on)) != 0)
+ return rc;
+ ACR_PUTFLAG(fd, ACR_SO_NONBLOCK, on);
+ }
+ break;
+ case ACR_OPT_IPV6_V6ONLY:
+#if defined(IPV6_V6ONLY)
+ if (setsockopt(fd->s, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on,
SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_SO_IPV6_V6ONLY, on);
+#else
+ rc = ACR_ENOTIMPL;
+#endif
+ break;
+ default:
+ rc = ACR_EINVAL;
+ break;
+ }
+ return rc;
+}
+
+ACR_NET_EXPORT(jint, SocketDescriptor, optset2)(JNI_STDARGS, jlong fp,
+ jint opt, jboolean val)
+{
+ int rc = 0;
+ int on = val == JNI_TRUE ? 1 : 0;
+ acr_sd_t *fd = J2P(fp, acr_sd_t *);
+
+ /* Set numeric values */
+ switch (opt) {
+ case ACR_OPT_TCP_DEFER_ACCEPT:
+#if defined(TCP_DEFER_ACCEPT)
+ if (on != ACR_HASFLAG(fd, ACR_TCP_DEFER_ACCEPT)) {
+ if (setsockopt(fd->s, IPPROTO_TCP, TCP_DEFER_ACCEPT, (void
*)&on, SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_TCP_DEFER_ACCEPT, on);
+ }
+#else
+ rc = ACR_ENOTIMPL;
+#endif
+ break;
+ case ACR_OPT_TCP_NODELAY:
+#if defined(TCP_NODELAY)
+ if (on != ACR_HASFLAG(fd, ACR_TCP_NODELAY)) {
+ if (setsockopt(fd->s, IPPROTO_TCP, TCP_NODELAY, (void *)&on,
SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_TCP_NODELAY, on);
+ }
+#else
+ rc = ACR_ENOTIMPL;
+#endif
+ break;
+ case ACR_OPT_TCP_NOPUSH:
+#if defined(TCP_CORK)
+ /* This presumes TCP_CORK and TCP_NODELAY work together
+ */
+ if (on != ACR_HASFLAG(fd, ACR_TCP_NOPUSH)) {
+ if (setsockopt(fd->s, IPPROTO_TCP, TCP_CORK, (void *)&on,
SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_TCP_NOPUSH, on);
+ }
+#else
+ rc = ACR_ENOTIMPL;
+#endif
+ break;
+ default:
+ rc = ACR_EINVAL;
+ break;
+ }
+ return rc;
+}
+
+ACR_NET_EXPORT(jboolean, SocketDescriptor, optget0)(JNI_STDARGS, jlong fp,
+ jint opt)
+{
+ int rc = 0;
+ jboolean rv = JNI_FALSE;
+ acr_sd_t *fd = J2P(fp, acr_sd_t *);
+
+ /* Set numeric values */
+ switch (opt) {
+ case ACR_OPT_SO_LINGER:
+ if (ACR_HASFLAG(fd, ACR_SO_LINGER))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_SO_TIMEOUT:
+ if (fd->timeout > 0)
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_SO_KEEPALIVE:
+ if (ACR_HASFLAG(fd, ACR_SO_KEEPALIVE))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_SO_REUSEADDR:
+ if (ACR_HASFLAG(fd, ACR_SO_REUSEADDR))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_SO_NONBLOCK:
+ if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_IPV6_V6ONLY:
+ if (ACR_HASFLAG(fd, ACR_SO_IPV6_V6ONLY))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_TCP_DEFER_ACCEPT:
+ if (ACR_HASFLAG(fd, ACR_TCP_DEFER_ACCEPT))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_TCP_NODELAY:
+ if (ACR_HASFLAG(fd, ACR_TCP_NODELAY))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_TCP_NOPUSH:
+ if (ACR_HASFLAG(fd, ACR_TCP_NOPUSH))
+ rv = JNI_TRUE;
+ break;
+ default:
+ rc = ACR_EINVAL;
+ break;
+ }
+ if (rc != 0)
+ ACR_THROW_NET_ERROR(rc);
+ return rv;
+}
+
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=1147363&r1=1147362&r2=1147363&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 Sat Jul
16 06:06:42 2011
@@ -248,7 +248,7 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
SOCKADDR_RELEASE(ba, aa);
sp->type = ACR_DT_LOCALSOCK;
- sp->flags = fd->flags;
+ sp->flags = fd->flags & ACR_SO_NONBLOCK;
sp->timeout = fd->timeout;
sp->refs = 1;
sp->s = sd;
@@ -259,6 +259,8 @@ ACR_NET_EXPORT(jlong, LocalServerEndpoin
}
else {
ACR_CLRFLAG(sp, ACR_SO_NONBLOCK);
+ if (sp->timeout == 0)
+ sp->timeout = -1;
}
return P2J(sp);
}
Modified: 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=1147363&r1=1147362&r2=1147363&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/sockopts.c Sat Jul
16 06:06:42 2011
@@ -42,47 +42,6 @@ ACR_NET_EXPORT(jboolean, SocketAddress,
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)
{
@@ -131,6 +90,7 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
}
}
else if (val < 0) {
+ val = -1;
if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
if ((rc = AcrNonblock(fd->s, 0)) != 0)
return rc;
@@ -152,3 +112,121 @@ ACR_NET_EXPORT(jint, SocketDescriptor, o
}
return rc;
}
+
+ACR_NET_EXPORT(jint, SocketDescriptor, optset1)(JNI_STDARGS, jlong fp,
+ jint opt, jboolean val)
+{
+ int rc = 0;
+ int on = val == JNI_TRUE ? 1 : 0;
+ acr_sd_t *fd = J2P(fp, acr_sd_t *);
+
+ /* Set numeric values */
+ switch (opt) {
+ case ACR_OPT_SO_KEEPALIVE:
+ if (on != ACR_HASFLAG(fd, ACR_SO_KEEPALIVE)) {
+ if (setsockopt(fd->s, SOL_SOCKET, SO_KEEPALIVE, (char *)&on,
SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_SO_KEEPALIVE, on);
+ }
+ break;
+ case ACR_OPT_SO_REUSEADDR:
+ if (on != ACR_HASFLAG(fd, ACR_SO_REUSEADDR)) {
+ if (setsockopt(fd->s, SOL_SOCKET, SO_REUSEADDR, (char *)&on,
SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_SO_REUSEADDR, on);
+ }
+ break;
+ case ACR_OPT_SO_NONBLOCK:
+ if (on != ACR_HASFLAG(fd, ACR_SO_NONBLOCK)) {
+ if ((rc = AcrNonblock(fd->s, on)) != 0)
+ return rc;
+ ACR_PUTFLAG(fd, ACR_SO_NONBLOCK, on);
+ }
+ break;
+ default:
+ rc = ACR_EINVAL;
+ break;
+ }
+ return rc;
+}
+
+ACR_NET_EXPORT(jint, SocketDescriptor, optset2)(JNI_STDARGS, jlong fp,
+ jint opt, jboolean val)
+{
+ int rc = 0;
+ int on = val == JNI_TRUE ? 1 : 0;
+ acr_sd_t *fd = J2P(fp, acr_sd_t *);
+
+ /* Set numeric values */
+ switch (opt) {
+ case ACR_OPT_TCP_NODELAY:
+ if (on != ACR_HASFLAG(fd, ACR_TCP_NODELAY)) {
+ if (setsockopt(fd->s, IPPROTO_TCP, TCP_NODELAY, (void *)&on,
SSIZEOF(int)) != 0)
+ return ACR_GET_NETOS_ERROR();
+ ACR_PUTFLAG(fd, ACR_TCP_NODELAY, on);
+ }
+ break;
+ case ACR_OPT_TCP_DEFER_ACCEPT:
+ case ACR_OPT_TCP_NOPUSH:
+ case ACR_OPT_IPV6_V6ONLY:
+ rc = ACR_ENOTIMPL;
+ break;
+ default:
+ rc = ACR_EINVAL;
+ break;
+ }
+ return rc;
+}
+
+ACR_NET_EXPORT(jboolean, SocketDescriptor, optget0)(JNI_STDARGS, jlong fp,
+ jint opt)
+{
+ int rc = 0;
+ jboolean rv = JNI_FALSE;
+ acr_sd_t *fd = J2P(fp, acr_sd_t *);
+
+ /* Set numeric values */
+ switch (opt) {
+ case ACR_OPT_SO_LINGER:
+ if (ACR_HASFLAG(fd, ACR_SO_LINGER))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_SO_TIMEOUT:
+ if (fd->timeout > 0)
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_SO_KEEPALIVE:
+ if (ACR_HASFLAG(fd, ACR_SO_KEEPALIVE))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_SO_REUSEADDR:
+ if (ACR_HASFLAG(fd, ACR_SO_REUSEADDR))
+ break;
+ case ACR_OPT_SO_NONBLOCK:
+ if (ACR_HASFLAG(fd, ACR_SO_NONBLOCK))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_IPV6_V6ONLY:
+ if (ACR_HASFLAG(fd, ACR_SO_IPV6_V6ONLY))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_TCP_DEFER_ACCEPT:
+ if (ACR_HASFLAG(fd, ACR_TCP_DEFER_ACCEPT))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_TCP_NODELAY:
+ if (ACR_HASFLAG(fd, ACR_TCP_NODELAY))
+ rv = JNI_TRUE;
+ break;
+ case ACR_OPT_TCP_NOPUSH:
+ if (ACR_HASFLAG(fd, ACR_TCP_NOPUSH))
+ rv = JNI_TRUE;
+ break;
+ default:
+ rc = ACR_EINVAL;
+ break;
+ }
+ if (rc != 0)
+ ACR_THROW_NET_ERROR(rc);
+ return rv;
+}
Modified:
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
URL:
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java?rev=1147363&r1=1147362&r2=1147363&view=diff
==============================================================================
---
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
(original)
+++
commons/sandbox/runtime/trunk/src/main/test/org/apache/commons/runtime/TestPosixEndpoint.java
Sat Jul 16 06:06:42 2011
@@ -94,6 +94,12 @@ public class TestPosixEndpoint extends A
fail("Acceptor shutdown failed " + x.toString());
}
running = false;
+ System.out.println("Accepting thread finished");
+ synchronized (sync) {
+ // Notify that we are ready to
+ // accept the connections
+ sync.notifyAll();
+ }
}
}
@@ -126,7 +132,7 @@ public class TestPosixEndpoint extends A
//
sync.wait();
}
- Thread.sleep(200);
+ Thread.sleep(100);
} catch (InterruptedException x) {
// Ignore
}