diff options
author | Jo Shields <directhex@apebox.org> | 2014-02-19 22:12:43 +0000 |
---|---|---|
committer | Jo Shields <directhex@apebox.org> | 2014-02-19 22:12:43 +0000 |
commit | 9972bf87b4f27d9c8f358ef8414ac1ab957a2f0f (patch) | |
tree | 5bb230c1d698659115f918e243c1d4b0aa4c7f51 /external/ikvm/openjdk/java/net/TwoStacksPlainSocketImpl.java | |
parent | d0a215f5626219ff7927f576588a777e5331c7be (diff) | |
download | mono-upstream/3.2.8+dfsg.tar.gz |
Imported Upstream version 3.2.8+dfsgupstream/3.2.8+dfsg
Diffstat (limited to 'external/ikvm/openjdk/java/net/TwoStacksPlainSocketImpl.java')
-rw-r--r-- | external/ikvm/openjdk/java/net/TwoStacksPlainSocketImpl.java | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/external/ikvm/openjdk/java/net/TwoStacksPlainSocketImpl.java b/external/ikvm/openjdk/java/net/TwoStacksPlainSocketImpl.java index 4179078852..12c1794f7d 100644 --- a/external/ikvm/openjdk/java/net/TwoStacksPlainSocketImpl.java +++ b/external/ikvm/openjdk/java/net/TwoStacksPlainSocketImpl.java @@ -66,10 +66,20 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl */ cli.System.Net.Sockets.Socket lastfd = null; - public TwoStacksPlainSocketImpl() {} + // true if this socket is exclusively bound + private final boolean exclusiveBind; - public TwoStacksPlainSocketImpl(FileDescriptor fd) { + // emulates SO_REUSEADDR when exclusiveBind is true + private boolean isReuseAddress; + + + public TwoStacksPlainSocketImpl(boolean exclBind) { + exclusiveBind = exclBind; + } + + public TwoStacksPlainSocketImpl(FileDescriptor fd, boolean exclBind) { this.fd = fd; + exclusiveBind = exclBind; } /** @@ -112,13 +122,33 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl InetAddressContainer in = new InetAddressContainer(); socketGetOption(opt, in); return in.addr; + } else if (opt == SO_REUSEADDR && exclusiveBind) { + // SO_REUSEADDR emulated when using exclusive bind + return isReuseAddress; } else return super.getOption(opt); } + @Override + void socketBind(InetAddress address, int port) throws IOException { + socketBind(address, port, exclusiveBind); + } + + @Override + void socketSetOption(int opt, boolean on, Object value) + throws SocketException + { + // SO_REUSEADDR emulated when using exclusive bind + if (opt == SO_REUSEADDR && exclusiveBind) + isReuseAddress = on; + else + socketNativeSetOption(opt, on, value); + } + /** * Closes the socket. */ + @Override protected void close() throws IOException { synchronized(fdLock) { if (fd != null || fd1 != null) { @@ -151,6 +181,7 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl } } + @Override void reset() throws IOException { if (fd != null || fd1 != null) { socketClose(); @@ -163,6 +194,7 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl /* * Return true if already closed or close is pending */ + @Override public boolean isClosedOrPending() { /* * Lock on fdLock to ensure that we wait if a @@ -191,9 +223,9 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl env.ThrowPendingException(); } - void socketBind(InetAddress address, int localport) throws IOException { + void socketBind(InetAddress address, int localport, boolean exclBind) throws IOException { ikvm.internal.JNI.JNIEnv env = new ikvm.internal.JNI.JNIEnv(); - TwoStacksPlainSocketImpl_c.socketBind(env, this, address, localport); + TwoStacksPlainSocketImpl_c.socketBind(env, this, address, localport, exclBind); env.ThrowPendingException(); } @@ -228,9 +260,9 @@ class TwoStacksPlainSocketImpl extends AbstractPlainSocketImpl env.ThrowPendingException(); } - void socketSetOption(int cmd, boolean on, Object value) throws SocketException { + void socketNativeSetOption(int cmd, boolean on, Object value) throws SocketException { ikvm.internal.JNI.JNIEnv env = new ikvm.internal.JNI.JNIEnv(); - TwoStacksPlainSocketImpl_c.socketSetOption(env, this, cmd, on, value); + TwoStacksPlainSocketImpl_c.socketNativeSetOption(env, this, cmd, on, value); env.ThrowPendingException(); } |