Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmallsql <smallsql>2011-07-09 20:52:12 +0400
committersmallsql <smallsql>2011-07-09 20:52:12 +0400
commit5314bdefb22153c8ceb89a7bc0dc29f6407c8beb (patch)
tree1731b2765dc9aaf771ba3786f3985da0bdd6c16f /openjdk/sun/nio/ch
parentce710fe1aef338ea44c6a77d0ed1772a601e9f4d (diff)
Add methods in SocketChannelImpl for Java 7
Diffstat (limited to 'openjdk/sun/nio/ch')
-rw-r--r--openjdk/sun/nio/ch/Net.java8
-rw-r--r--openjdk/sun/nio/ch/SocketChannelImpl.java90
2 files changed, 98 insertions, 0 deletions
diff --git a/openjdk/sun/nio/ch/Net.java b/openjdk/sun/nio/ch/Net.java
index a6b1bf9e..1d7fa47c 100644
--- a/openjdk/sun/nio/ch/Net.java
+++ b/openjdk/sun/nio/ch/Net.java
@@ -56,6 +56,14 @@ class Net { // package-private
}
};
+ /**
+ * Tells whether dual-IPv4/IPv6 sockets should be used.
+ */
+ static boolean isIPv6Available() {
+ new NotYetImplementedError().printStackTrace(); //TODO JDK7
+ return true;
+ }
+
static FileDescriptor serverSocket(boolean stream) throws IOException
{
return socket(stream);
diff --git a/openjdk/sun/nio/ch/SocketChannelImpl.java b/openjdk/sun/nio/ch/SocketChannelImpl.java
index 971d644e..cb576b46 100644
--- a/openjdk/sun/nio/ch/SocketChannelImpl.java
+++ b/openjdk/sun/nio/ch/SocketChannelImpl.java
@@ -33,6 +33,9 @@ import java.net.*;
import java.nio.ByteBuffer;
import java.nio.channels.*;
import java.nio.channels.spi.*;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
/**
@@ -118,6 +121,93 @@ class SocketChannelImpl
}
}
+ public SocketAddress getLocalAddress() throws IOException {
+ synchronized (stateLock) {
+ if (!isOpen())
+ throw new ClosedChannelException();
+ return localAddress;
+ }
+ }
+
+ public SocketAddress getRemoteAddress() throws IOException {
+ synchronized (stateLock) {
+ if (!isOpen())
+ throw new ClosedChannelException();
+ return remoteAddress;
+ }
+ }
+
+ public <T> SocketChannel setOption(SocketOption<T> name, T value)
+ throws IOException
+ {
+ if (name == null)
+ throw new NullPointerException();
+ if (!supportedOptions().contains(name))
+ throw new UnsupportedOperationException("'" + name + "' not supported");
+
+ synchronized (stateLock) {
+ if (!isOpen())
+ throw new ClosedChannelException();
+
+ // special handling for IP_TOS: no-op when IPv6
+ if (name == StandardSocketOptions.IP_TOS) {
+ if (!Net.isIPv6Available())
+ Net.setSocketOption(fd, StandardProtocolFamily.INET, name, value);
+ return this;
+ }
+
+ // no options that require special handling
+ Net.setSocketOption(fd, Net.UNSPEC, name, value);
+ return this;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T getOption(SocketOption<T> name)
+ throws IOException
+ {
+ if (name == null)
+ throw new NullPointerException();
+ if (!supportedOptions().contains(name))
+ throw new UnsupportedOperationException("'" + name + "' not supported");
+
+ synchronized (stateLock) {
+ if (!isOpen())
+ throw new ClosedChannelException();
+
+ // special handling for IP_TOS: always return 0 when IPv6
+ if (name == StandardSocketOptions.IP_TOS) {
+ return (Net.isIPv6Available()) ? (T) Integer.valueOf(0) :
+ (T) Net.getSocketOption(fd, StandardProtocolFamily.INET, name);
+ }
+
+ // no options that require special handling
+ return (T) Net.getSocketOption(fd, Net.UNSPEC, name);
+ }
+ }
+
+ private static class DefaultOptionsHolder {
+ static final Set<SocketOption<?>> defaultOptions = defaultOptions();
+
+ private static Set<SocketOption<?>> defaultOptions() {
+ HashSet<SocketOption<?>> set = new HashSet<SocketOption<?>>(8);
+ set.add(StandardSocketOptions.SO_SNDBUF);
+ set.add(StandardSocketOptions.SO_RCVBUF);
+ set.add(StandardSocketOptions.SO_KEEPALIVE);
+ set.add(StandardSocketOptions.SO_REUSEADDR);
+ set.add(StandardSocketOptions.SO_LINGER);
+ set.add(StandardSocketOptions.TCP_NODELAY);
+ // additional options required by socket adaptor
+ set.add(StandardSocketOptions.IP_TOS);
+ set.add(ExtendedSocketOption.SO_OOBINLINE);
+ return Collections.unmodifiableSet(set);
+ }
+ }
+
+ public final Set<SocketOption<?>> supportedOptions() {
+ return DefaultOptionsHolder.defaultOptions;
+ }
+
private boolean ensureReadOpen() throws ClosedChannelException {
synchronized (stateLock) {
if (!isOpen())