[maven-release-plugin] copy for tag 2.0.6
git-svn-id: https://svn.apache.org/repos/asf/mina/mina/tags/2.0.6@1392839 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
index 7bd9188..b339da6 100644
--- a/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
+++ b/mina-core/src/main/java/org/apache/mina/transport/socket/nio/NioDatagramAcceptor.java
@@ -19,6 +19,9 @@
*/
package org.apache.mina.transport.socket.nio;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.DatagramChannel;
@@ -139,7 +142,25 @@
@Override
protected SocketAddress localAddress(DatagramChannel handle) throws Exception {
- return handle.socket().getLocalSocketAddress();
+ InetSocketAddress inetSocketAddress = (InetSocketAddress) handle.socket().getLocalSocketAddress();
+ InetAddress inetAddress = inetSocketAddress.getAddress();
+
+ if ((inetAddress instanceof Inet6Address) && (((Inet6Address) inetAddress).isIPv4CompatibleAddress())) {
+ // Ugly hack to workaround a problem on linux : the ANY address is always converted to IPV6
+ // even if the original address was an IPV4 address. We do store the two IPV4 and IPV6
+ // ANY address in the map.
+ byte[] ipV6Address = ((Inet6Address) inetAddress).getAddress();
+ byte[] ipV4Address = new byte[4];
+
+ for (int i = 0; i < 4; i++) {
+ ipV4Address[i] = ipV6Address[12 + i];
+ }
+
+ InetAddress inet4Adress = Inet4Address.getByAddress(ipV4Address);
+ return new InetSocketAddress(inet4Adress, inetSocketAddress.getPort());
+ } else {
+ return inetSocketAddress;
+ }
}
@Override
diff --git a/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java b/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java
index a2a884d..914e770 100644
--- a/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java
+++ b/mina-core/src/main/java/org/apache/mina/util/AvailablePortFinder.java
@@ -62,14 +62,22 @@
}
/**
- * Gets the next available port starting at the lowest port number.
+ * Gets an available port, selected by the system.
*
* @throws NoSuchElementException if there are no ports available
*/
public static int getNextAvailable() {
+ ServerSocket serverSocket = null;
+
try {
// Here, we simply return an available port found by the system
- return new ServerSocket(0).getLocalPort();
+ serverSocket = new ServerSocket(0);
+ int port = serverSocket.getLocalPort();
+
+ // Don't forget to close the socket...
+ serverSocket.close();
+
+ return port;
} catch (IOException ioe) {
throw new NoSuchElementException(ioe.getMessage());
}
@@ -107,6 +115,7 @@
ServerSocket ss = null;
DatagramSocket ds = null;
+
try {
ss = new ServerSocket(port);
ss.setReuseAddress(true);