diff --git a/build.xml b/build.xml
index 093ab53..266f7c5 100644
--- a/build.xml
+++ b/build.xml
@@ -35,21 +35,26 @@
+
+
+
+
+
-
+ target="1.5">
+
+
-
MuxServerSocketChannel
+ > MuxServerSocketChannelFactory
.SOCKET_CHANNEL_READ_TIMEOUT)
{
// De-register from the Selector.
@@ -1456,7 +1457,8 @@ public class MultiplexingTcpHostHarvester
try
{
readSelector.select(
- MuxServerSocketChannel.SOCKET_CHANNEL_READ_TIMEOUT
+ MuxServerSocketChannelFactory
+ .SOCKET_CHANNEL_READ_TIMEOUT
/ 2);
}
catch (IOException ioe)
diff --git a/src/org/ice4j/socket/DelegatingServerSocketChannel.java b/src/org/ice4j/socket/BaseDelegatingServerSocketChannel.java
similarity index 73%
rename from src/org/ice4j/socket/DelegatingServerSocketChannel.java
rename to src/org/ice4j/socket/BaseDelegatingServerSocketChannel.java
index 80bd498..b675c44 100644
--- a/src/org/ice4j/socket/DelegatingServerSocketChannel.java
+++ b/src/org/ice4j/socket/BaseDelegatingServerSocketChannel.java
@@ -11,8 +11,6 @@ import java.net.*;
import java.nio.channels.*;
import java.util.*;
-import sun.nio.ch.*;
-
/**
* Implements a {@code ServerSocketChannel} which delegates (its method calls)
* to another {@code ServerSocketChannel}. In other words, the former wraps the
@@ -20,9 +18,8 @@ import sun.nio.ch.*;
*
* @author Lyubomir Marinov
*/
-public class DelegatingServerSocketChannel
+public class BaseDelegatingServerSocketChannel
extends ServerSocketChannel
- implements SelChImpl
{
/**
* The {@link ServerSocketChannel} this instance delegates (its method
@@ -30,12 +27,6 @@ public class DelegatingServerSocketChannel
*/
protected final T delegate;
- /**
- * The view of {@link #delegate} as a SelChImpl interface instance
- * required by {@link Selector} and related functionality.
- */
- protected final SelChImpl delegateAsSelChImpl;
-
/**
* The {@code ServerSocket} to be reported by this instance.
*/
@@ -47,20 +38,18 @@ public class DelegatingServerSocketChannel
private final Object socketSyncRoot = new Object();
/**
- * Initializes a new {@code DelegatingServerSocketChannel} instance which is
- * to delegate (its method calls) to a specific {@code ServerSocketChannel}.
+ * Initializes a new {@code BaseDelegatingServerSocketChannel} instance
+ * which is to delegate (its method calls) to a specific
+ * {@code ServerSocketChannel}.
*
* @param delegate the {@code ServerSocketChannel} the new instance is to
* delegate (its method calls) to
*/
- public DelegatingServerSocketChannel(T delegate)
+ public BaseDelegatingServerSocketChannel(T delegate)
{
super(delegate.provider());
this.delegate = delegate;
-
- delegateAsSelChImpl
- = (delegate instanceof SelChImpl) ? (SelChImpl) delegate : null;
}
/**
@@ -90,28 +79,6 @@ public class DelegatingServerSocketChannel
return this;
}
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public FileDescriptor getFD()
- {
- return delegateAsSelChImpl.getFD();
- }
-
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public int getFDVal()
- {
- return delegateAsSelChImpl.getFDVal();
- }
-
/**
* {@inheritDoc}
*
@@ -193,7 +160,8 @@ public class DelegatingServerSocketChannel
}
/**
- * Determines whether this {@code DelegatingServerSocketChannel} is bound.
+ * Determines whether this {@code BaseDelegatingServerSocketChannel} is
+ * bound.
*
* @return {@code true} if this instancei bound; otherwise, {@code false}
*/
@@ -209,18 +177,6 @@ public class DelegatingServerSocketChannel
}
}
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public void kill()
- throws IOException
- {
- delegateAsSelChImpl.kill();
- }
-
/**
* {@inheritDoc}
*
@@ -285,37 +241,4 @@ public class DelegatingServerSocketChannel
{
return delegate.supportedOptions();
}
-
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk)
- {
- delegateAsSelChImpl.translateAndSetInterestOps(ops, sk);
- }
-
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk)
- {
- return delegateAsSelChImpl.translateAndSetReadyOps(ops, sk);
- }
-
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk)
- {
- return delegateAsSelChImpl.translateAndUpdateReadyOps(ops, sk);
- }
}
diff --git a/src/org/ice4j/socket/DelegatingSocketChannel.java b/src/org/ice4j/socket/BaseDelegatingSocketChannel.java
similarity index 78%
rename from src/org/ice4j/socket/DelegatingSocketChannel.java
rename to src/org/ice4j/socket/BaseDelegatingSocketChannel.java
index b50bb8b..3c0118c 100644
--- a/src/org/ice4j/socket/DelegatingSocketChannel.java
+++ b/src/org/ice4j/socket/BaseDelegatingSocketChannel.java
@@ -12,29 +12,20 @@ import java.nio.*;
import java.nio.channels.*;
import java.util.*;
-import sun.nio.ch.*;
-
/**
* Implements a {@code SocketChannel} which delegates (its method calls) to
* another {@code SocketChannel}. In other words, the former wraps the latter.
*
* @author Lyubomir Marinov
*/
-public class DelegatingSocketChannel
+public class BaseDelegatingSocketChannel
extends SocketChannel
- implements SelChImpl
{
/**
* The {@link SocketChannel} this instance delegates (its method calls) to.
*/
protected final T delegate;
- /**
- * The view of {@link #delegate} as a SelChImpl interface instance
- * required by {@link Selector} and related functionality.
- */
- protected final SelChImpl delegateAsSelChImpl;
-
/**
* The {@code Socket} to be reported by this instance.
*/
@@ -46,20 +37,17 @@ public class DelegatingSocketChannel
private final Object socketSyncRoot = new Object();
/**
- * Initializes a new {@code DelegatingSocketChannel} instance which is to
- * delegate (its method calls) to a specific {@code SocketChannel}.
+ * Initializes a new {@code BaseDelegatingSocketChannel} instance which is
+ * to delegate (its method calls) to a specific {@code SocketChannel}.
*
* @param delegate the {@code SocketChannel} the new instance is to delegate
* (its method calls) to
*/
- public DelegatingSocketChannel(T delegate)
+ public BaseDelegatingSocketChannel(T delegate)
{
super(delegate.provider());
this.delegate = delegate;
-
- delegateAsSelChImpl
- = (delegate instanceof SelChImpl) ? (SelChImpl) delegate : null;
}
/**
@@ -99,28 +87,6 @@ public class DelegatingSocketChannel
return delegate.finishConnect();
}
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public FileDescriptor getFD()
- {
- return delegateAsSelChImpl.getFD();
- }
-
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public int getFDVal()
- {
- return delegateAsSelChImpl.getFDVal();
- }
-
/**
* {@inheritDoc}
*
@@ -218,18 +184,6 @@ public class DelegatingSocketChannel
return delegate.isConnectionPending();
}
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public void kill()
- throws IOException
- {
- delegateAsSelChImpl.kill();
- }
-
/**
* {@inheritDoc}
*
@@ -345,39 +299,6 @@ public class DelegatingSocketChannel
return delegate.supportedOptions();
}
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk)
- {
- delegateAsSelChImpl.translateAndSetInterestOps(ops, sk);
- }
-
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk)
- {
- return delegateAsSelChImpl.translateAndSetReadyOps(ops, sk);
- }
-
- /**
- * {@inheritDoc}
- *
- * Forwards to {@link #delegate}.
- */
- @Override
- public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk)
- {
- return delegateAsSelChImpl.translateAndUpdateReadyOps(ops, sk);
- }
-
/**
* {@inheritDoc}
*
diff --git a/src/org/ice4j/socket/DelegatingSocket.java b/src/org/ice4j/socket/DelegatingSocket.java
index 8cea650..6ffb064 100644
--- a/src/org/ice4j/socket/DelegatingSocket.java
+++ b/src/org/ice4j/socket/DelegatingSocket.java
@@ -210,15 +210,15 @@ public class DelegatingSocket
if (delegate instanceof DelegatingSocket)
{
- // FIXME DelegatingSocketChannel was in need of a Socket which wraps
- // another Socket and reports a specific SocketChannel. Since
- // DelegatingSocket does that, DelegatingSocketChannel used it.
+ // FIXME BaseDelegatingSocketChannel was in need of a Socket which
+ // wraps another Socket and reports a specific SocketChannel. Since
+ // DelegatingSocket does that, BaseDelegatingSocketChannel used it.
// Unfortunately, it turned out after much debugging that
// DelegatingSocket has the additional function of flagging where
// UDP packets sent over TCP are to be framed. As a temporary fix,
// do not treat the sockets of DelegatingSocketChannel as
// DelegatingSockets.
- if (channel instanceof DelegatingSocketChannel)
+ if (channel instanceof BaseDelegatingSocketChannel)
delegateAsDelegatingSocket = null;
else
delegateAsDelegatingSocket = (DelegatingSocket) delegate;
diff --git a/src/org/ice4j/socket/HttpDemuxFilter.java b/src/org/ice4j/socket/HttpDemuxFilter.java
index 14560cc..1cfd698 100644
--- a/src/org/ice4j/socket/HttpDemuxFilter.java
+++ b/src/org/ice4j/socket/HttpDemuxFilter.java
@@ -13,7 +13,7 @@ import org.ice4j.ice.harvest.*;
/**
* Implements a {@link DatagramPacketFilter} which allows demultiplexing HTTP(S)
- * out of {@link MuxServerSocketChannel}. Accepts HTTP, SSL v2, and TLS. Rejects
+ * out of {@code MuxServerSocketChannel}. Accepts HTTP, SSL v2, and TLS. Rejects
* Google TURN SSLTCP.
*
* @author Lyubomir Marinov
diff --git a/src/org/ice4j/socket/MuxServerSocketChannelFactory.java b/src/org/ice4j/socket/MuxServerSocketChannelFactory.java
new file mode 100644
index 0000000..7828a60
--- /dev/null
+++ b/src/org/ice4j/socket/MuxServerSocketChannelFactory.java
@@ -0,0 +1,250 @@
+/*
+ * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
+ * Maintained by the SIP Communicator community (http://sip-communicator.org).
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package org.ice4j.socket;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.net.*;
+import java.nio.channels.*;
+import java.util.*;
+import java.util.logging.*;
+
+/**
+ * If supported by the runtime, initializes {@link ServerSocketChannel}s which
+ * are capable of sharing their listening endpoints with multiple others like
+ * them.
+ *
+ * @author Lyubomir Marinov
+ */
+public class MuxServerSocketChannelFactory
+{
+ /**
+ * The {@code Logger} used by the {@code MuxServerSocketChannelFactory}
+ * class (and its instances) to print debug information.
+ */
+ private static final Logger logger
+ = Logger.getLogger(MuxServerSocketChannelFactory.class.getName());
+
+ /**
+ * The reflection of the {@code openAndBind} method of the
+ * {@code MuxServerSocketChannel} class.
+ */
+ private static final Method OPEN_AND_BIND_METHOD;
+
+ /**
+ * The maximum number of milliseconds to wait for an accepted
+ * {@code SocketChannel} to provide incoming/readable data before it is
+ * considered abandoned by the client.
+ */
+ public static final int SOCKET_CHANNEL_READ_TIMEOUT = 15 * 1000;
+
+ /**
+ * The name of the {@code boolean} property of the {@code socket} property
+ * of the {@code ServerSocketChannel} returned by {@link #openAndBind(Map,
+ * SocketAddress, int, DatagramPacketFilter)} which specifies the value of
+ * the {@code SO_REUSEADDR} socket option.
+ */
+ public static final String SOCKET_REUSE_ADDRESS_PROPERTY_NAME
+ = "socket.reuseAddress";
+
+ static
+ {
+ Class> clazz;
+
+ try
+ {
+ clazz
+ = Class.forName("org.ice4j.socket.jdk8.MuxServerSocketChannel");
+ }
+ catch (ClassNotFoundException cnfex)
+ {
+ // The class cannot be located probably because ICE4J was not built
+ // on JDK 8.
+ clazz = null;
+ logger.warning(
+ "ICE4J does not support sharing of listening endpoints"
+ + " (probably because it was not built on JDK 8).");
+ }
+ catch (LinkageError lerr)
+ {
+ // The linkage fails probably because ICE4J was built on JDK 8 but
+ // is not run on JDK 8.
+ clazz = null;
+ logger.warning(
+ "ICE4J does not support sharing of listening endpoints"
+ + " (probably because it is not running on JDK 8).");
+ }
+ Method method;
+
+ if (clazz == null)
+ {
+ method = null;
+ }
+ else
+ {
+ try
+ {
+ method
+ = clazz.getDeclaredMethod(
+ "openAndBind",
+ Map.class,
+ SocketAddress.class,
+ int.class,
+ DatagramPacketFilter.class);
+ }
+ catch (NoSuchMethodException nsmex)
+ {
+ throw new RuntimeException(nsmex);
+ }
+ }
+ OPEN_AND_BIND_METHOD = method;
+ }
+
+ /**
+ * Closes a {@code Channel} and swallows any {@link IOException}.
+ *
+ * @param channel the {@code Channel} to close
+ */
+ public static void closeNoExceptions(Channel channel)
+ {
+ try
+ {
+ channel.close();
+ }
+ catch (IOException ioe)
+ {
+ }
+ }
+
+ /**
+ * Opens and binds a new {@code MuxServerSocketChannel} instance if
+ * supported by the runtime. If there are other (existing)
+ * {@code MuxServerSocketChannel} open and bound on the specified listening
+ * {@code endpoint}, the new instance will share it with them. If the
+ * sharing of listening endpoints is not supported by the runtime, falls
+ * back to {@link #openAndBindServerSocketChannel(Map, SocketAddress, int)}.
+ *
+ * @param properties a {@code Map} of the values to be assigned to
+ * properties of the underlying {@link ServerSocketChannel} which is to
+ * actually listen on the specified {@code endpoint}. If the new instance is
+ * not the first to open and bind the specified {@code endpoint}, the
+ * {@code properties} and their respective values may not be used.
+ * @param endpoint the IP and port the new instance is to bind to
+ * @param backlog the requested maximum number of pending incoming
+ * connections to be queued. If the new instance is not the first to open
+ * and bind the specified {@code endpoint}, the value may not be used.
+ * @param filter the {@code DatagramPacketFilter} to demultiplex (i.e.
+ * recognize) the content meant for the new instance
+ * @return a new {@code MuxServerSocketChannel} instance open and bound on
+ * the specified listening {@code endpoint}
+ * @throws IOException if an I/O error occurs
+ */
+ public static ServerSocketChannel openAndBindMuxServerSocketChannel(
+ Map properties,
+ SocketAddress endpoint,
+ int backlog,
+ DatagramPacketFilter filter)
+ throws IOException
+ {
+ Method method = OPEN_AND_BIND_METHOD;
+
+ if (method == null)
+ {
+ return
+ openAndBindServerSocketChannel(properties, endpoint, backlog);
+ }
+ else
+ {
+ try
+ {
+ return
+ (ServerSocketChannel)
+ method.invoke(
+ null,
+ properties, endpoint, backlog, filter);
+ }
+ catch (IllegalAccessException iaex)
+ {
+ IllegalAccessError iaerr
+ = new IllegalAccessError(iaex.getMessage());
+
+ iaerr.initCause(iaex);
+ throw iaerr;
+ }
+ catch (InvocationTargetException itex)
+ {
+ Throwable cause = itex.getCause();
+
+ if (cause == null)
+ throw new RuntimeException(itex);
+ else if (cause instanceof Error)
+ throw (Error) cause;
+ else if (cause instanceof IOException)
+ throw (IOException) cause;
+ else if (cause instanceof RuntimeException)
+ throw (RuntimeException) cause;
+ else
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+
+ /**
+ * Opens and binds a new {@code ServerSocketChannel} instance.
+ *
+ * @param properties a {@code Map} of the values to be assigned to
+ * properties of the underlying {@link ServerSocketChannel} which is to
+ * actually listen on the specified {@code endpoint}. If the new instance is
+ * not the first to open and bind the specified {@code endpoint}, the
+ * {@code properties} and their respective values may not be used.
+ * @param endpoint the IP and port the new instance is to bind to
+ * @param backlog the requested maximum number of pending incoming
+ * connections to be queued. If the new instance is not the first to open
+ * and bind the specified {@code endpoint}, the value may not be used.
+ * @return a new {@code ServerSocketChannel} instance open and bound on the
+ * specified listening {@code endpoint}
+ * @throws IOException if an I/O error occurs
+ */
+ public static ServerSocketChannel openAndBindServerSocketChannel(
+ Map properties,
+ SocketAddress endpoint,
+ int backlog)
+ throws IOException
+ {
+ ServerSocketChannel channel = ServerSocketChannel.open();
+ // Apply the specified properties.
+ ServerSocket socket = channel.socket();
+
+ if (properties != null && !properties.isEmpty())
+ {
+ for (Map.Entry property
+ : properties.entrySet())
+ {
+ String name = property.getKey();
+
+ if (SOCKET_REUSE_ADDRESS_PROPERTY_NAME.equals(name))
+ {
+ Object value = property.getValue();
+ boolean on;
+
+ if (value == null)
+ on = false;
+ else if (value instanceof Boolean)
+ on = ((Boolean) value).booleanValue();
+ else
+ on = Boolean.valueOf(value.toString());
+
+ socket.setReuseAddress(on);
+ }
+ }
+ }
+
+ socket.bind(endpoint, backlog);
+
+ return channel;
+ }
+}
diff --git a/src/org/ice4j/socket/jdk8/DelegatingServerSocketChannel.java b/src/org/ice4j/socket/jdk8/DelegatingServerSocketChannel.java
new file mode 100644
index 0000000..db766ee
--- /dev/null
+++ b/src/org/ice4j/socket/jdk8/DelegatingServerSocketChannel.java
@@ -0,0 +1,114 @@
+/*
+ * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
+ * Maintained by the SIP Communicator community (http://sip-communicator.org).
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package org.ice4j.socket.jdk8;
+
+import java.io.*;
+import java.nio.channels.*;
+
+import org.ice4j.socket.*;
+
+import sun.nio.ch.*;
+
+/**
+ * Implements a {@code ServerSocketChannel} which delegates (its method calls)
+ * to another {@code ServerSocketChannel}. In other words, the former wraps the
+ * latter.
+ *
+ * @author Lyubomir Marinov
+ */
+class DelegatingServerSocketChannel
+ extends BaseDelegatingServerSocketChannel
+ implements SelChImpl
+{
+ /**
+ * The view of {@link #delegate} as a SelChImpl interface instance
+ * required by {@link Selector} and related functionality.
+ */
+ protected final SelChImpl delegateAsSelChImpl;
+
+ /**
+ * Initializes a new {@code DelegatingServerSocketChannel} instance which is
+ * to delegate (its method calls) to a specific {@code ServerSocketChannel}.
+ *
+ * @param delegate the {@code ServerSocketChannel} the new instance is to
+ * delegate (its method calls) to
+ */
+ public DelegatingServerSocketChannel(T delegate)
+ {
+ super(delegate);
+
+ delegateAsSelChImpl
+ = (delegate instanceof SelChImpl) ? (SelChImpl) delegate : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public FileDescriptor getFD()
+ {
+ return delegateAsSelChImpl.getFD();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public int getFDVal()
+ {
+ return delegateAsSelChImpl.getFDVal();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public void kill()
+ throws IOException
+ {
+ delegateAsSelChImpl.kill();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk)
+ {
+ delegateAsSelChImpl.translateAndSetInterestOps(ops, sk);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk)
+ {
+ return delegateAsSelChImpl.translateAndSetReadyOps(ops, sk);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk)
+ {
+ return delegateAsSelChImpl.translateAndUpdateReadyOps(ops, sk);
+ }
+}
diff --git a/src/org/ice4j/socket/jdk8/DelegatingSocketChannel.java b/src/org/ice4j/socket/jdk8/DelegatingSocketChannel.java
new file mode 100644
index 0000000..4bb91a4
--- /dev/null
+++ b/src/org/ice4j/socket/jdk8/DelegatingSocketChannel.java
@@ -0,0 +1,113 @@
+/*
+ * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
+ * Maintained by the SIP Communicator community (http://sip-communicator.org).
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package org.ice4j.socket.jdk8;
+
+import java.io.*;
+import java.nio.channels.*;
+
+import org.ice4j.socket.*;
+
+import sun.nio.ch.*;
+
+/**
+ * Implements a {@code SocketChannel} which delegates (its method calls) to
+ * another {@code SocketChannel}. In other words, the former wraps the latter.
+ *
+ * @author Lyubomir Marinov
+ */
+class DelegatingSocketChannel
+ extends BaseDelegatingSocketChannel
+ implements SelChImpl
+{
+ /**
+ * The view of {@link #delegate} as a SelChImpl interface instance
+ * required by {@link Selector} and related functionality.
+ */
+ protected final SelChImpl delegateAsSelChImpl;
+
+ /**
+ * Initializes a new {@code DelegatingSocketChannel} instance which is to
+ * delegate (its method calls) to a specific {@code SocketChannel}.
+ *
+ * @param delegate the {@code SocketChannel} the new instance is to delegate
+ * (its method calls) to
+ */
+ public DelegatingSocketChannel(T delegate)
+ {
+ super(delegate);
+
+ delegateAsSelChImpl
+ = (delegate instanceof SelChImpl) ? (SelChImpl) delegate : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public FileDescriptor getFD()
+ {
+ return delegateAsSelChImpl.getFD();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public int getFDVal()
+ {
+ return delegateAsSelChImpl.getFDVal();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public void kill()
+ throws IOException
+ {
+ delegateAsSelChImpl.kill();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public void translateAndSetInterestOps(int ops, SelectionKeyImpl sk)
+ {
+ delegateAsSelChImpl.translateAndSetInterestOps(ops, sk);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public boolean translateAndSetReadyOps(int ops, SelectionKeyImpl sk)
+ {
+ return delegateAsSelChImpl.translateAndSetReadyOps(ops, sk);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Forwards to {@link #delegate}.
+ */
+ @Override
+ public boolean translateAndUpdateReadyOps(int ops, SelectionKeyImpl sk)
+ {
+ return delegateAsSelChImpl.translateAndUpdateReadyOps(ops, sk);
+ }
+}
diff --git a/src/org/ice4j/socket/MuxServerSocketChannel.java b/src/org/ice4j/socket/jdk8/MuxServerSocketChannel.java
similarity index 96%
rename from src/org/ice4j/socket/MuxServerSocketChannel.java
rename to src/org/ice4j/socket/jdk8/MuxServerSocketChannel.java
index 5a0d8a0..ea0ad65 100644
--- a/src/org/ice4j/socket/MuxServerSocketChannel.java
+++ b/src/org/ice4j/socket/jdk8/MuxServerSocketChannel.java
@@ -4,7 +4,7 @@
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
-package org.ice4j.socket;
+package org.ice4j.socket.jdk8;
import java.io.*;
import java.net.*;
@@ -13,6 +13,7 @@ import java.nio.channels.*;
import java.util.*;
import org.ice4j.ice.harvest.*;
+import org.ice4j.socket.*;
/**
* Implements a {@link ServerSocketChannel} which is capable of sharing its
@@ -41,16 +42,8 @@ public class MuxServerSocketChannel
* {@code SocketChannel} to provide incoming/readable data before it is
* considered abandoned by the client.
*/
- public static final int SOCKET_CHANNEL_READ_TIMEOUT = 15 * 1000;
-
- /**
- * The name of the boolean property of the socket property
- * of the ServerSocketChannel returned by {@link #openAndBind(Map,
- * SocketAddress, int, DatagramPacketFilter)} which specifies the value of
- * the SO_REUSEADDR socket option.
- */
- public static final String SOCKET_REUSE_ADDRESS_PROPERTY_NAME
- = "socket.reuseAddress";
+ private static final int SOCKET_CHANNEL_READ_TIMEOUT
+ = MuxServerSocketChannelFactory.SOCKET_CHANNEL_READ_TIMEOUT;
/**
* Asserts that t is not null by throwing a
@@ -80,13 +73,7 @@ public class MuxServerSocketChannel
*/
public static void closeNoExceptions(Channel channel)
{
- try
- {
- channel.close();
- }
- catch (IOException ioe)
- {
- }
+ MuxServerSocketChannelFactory.closeNoExceptions(channel);
}
/**
@@ -594,35 +581,12 @@ public class MuxServerSocketChannel
muxingChannel = findMuxingServerSocketChannel(endpoint);
if (muxingChannel == null)
{
- ServerSocketChannel channel = ServerSocketChannel.open();
- // Apply the specified properties.
- ServerSocket socket = channel.socket();
-
- if (properties != null && !properties.isEmpty())
- {
- for (Map.Entry property
- : properties.entrySet())
- {
- String name = property.getKey();
-
- if (SOCKET_REUSE_ADDRESS_PROPERTY_NAME.equals(name))
- {
- Object value = property.getValue();
- boolean on;
-
- if (value == null)
- on = false;
- else if (value instanceof Boolean)
- on = ((Boolean) value).booleanValue();
- else
- on = Boolean.valueOf(value.toString());
-
- socket.setReuseAddress(on);
- }
- }
- }
-
- socket.bind(endpoint, backlog);
+ ServerSocketChannel channel
+ = MuxServerSocketChannelFactory
+ .openAndBindServerSocketChannel(
+ properties,
+ endpoint,
+ backlog);
muxingChannel = new MuxingServerSocketChannel(channel);
addMuxingServerSocketChannel(muxingChannel);
diff --git a/src/org/ice4j/socket/PreReadSocketChannel.java b/src/org/ice4j/socket/jdk8/PreReadSocketChannel.java
similarity index 97%
rename from src/org/ice4j/socket/PreReadSocketChannel.java
rename to src/org/ice4j/socket/jdk8/PreReadSocketChannel.java
index c75dbfa..c26f2d4 100644
--- a/src/org/ice4j/socket/PreReadSocketChannel.java
+++ b/src/org/ice4j/socket/jdk8/PreReadSocketChannel.java
@@ -4,7 +4,7 @@
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
-package org.ice4j.socket;
+package org.ice4j.socket.jdk8;
import java.io.*;
import java.net.*;
@@ -17,7 +17,7 @@ import java.nio.channels.*;
*
* @author Lyubomir Marinov
*/
-public class PreReadSocketChannel
+class PreReadSocketChannel
extends DelegatingSocketChannel
{
/**