I'm not sure whether this is an issue or not.  We have experienced that the
NioSocketAcceptor does not unbind the 0.0.0.0 address.  When you
bind(0.0.0.0), the NioSocketAcceptor gets a SocketAddress from the
ServerSocketChannel containing a slightly different address:

NioSocketAcceptor.java:
    protected SocketAddress localAddress(ServerSocketChannel handle)
            throws Exception {
        return handle.socket().getLocalSocketAddress();
    }


The address returned by handle.socket().getLocalSocketAddress() is
"0.0.0.0.0.0.0.0/<port>".  Then the acceptor keeps that address and when you
try to unbind() "0.0.0.0/<port>", it does not find the address and does not
unbind it.  Our workaround is to call unbind() without any parameters, so
that it effectivelly unbind all local addresses.

I've attached a patch (against MINA-2.0 M4) containing a unit test for this
use case.

Best regards,

Célio
Index: core/src/test/java/org/apache/mina/transport/socket/nio/BindingOnAllInterfacesTest.java
===================================================================
--- core/src/test/java/org/apache/mina/transport/socket/nio/BindingOnAllInterfacesTest.java	(revision 0)
+++ core/src/test/java/org/apache/mina/transport/socket/nio/BindingOnAllInterfacesTest.java	(revision 0)
@@ -0,0 +1,34 @@
+package org.apache.mina.transport.socket.nio;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.core.service.IoHandlerAdapter;
+
+public class BindingOnAllInterfacesTest extends TestCase {
+    private static final InetSocketAddress ALL_INTERFACES = new InetSocketAddress("0.0.0.0", 10999);
+    
+    private NioSocketAcceptor acceptor;
+    
+    public void setUp() {
+        acceptor = new NioSocketAcceptor();
+        acceptor.setHandler(new IoHandlerAdapter());
+    }
+    
+    public void tearDown() {
+        acceptor.unbind();
+    }
+    
+    public void testLocalAddress() throws IOException {
+        acceptor.bind(ALL_INTERFACES);
+        assertEquals(ALL_INTERFACES, acceptor.getLocalAddress());
+    }
+
+    public void testUnbind() throws IOException {
+        acceptor.bind(ALL_INTERFACES);
+        acceptor.unbind(ALL_INTERFACES);
+        acceptor.bind(ALL_INTERFACES);
+    }
+}

Reply via email to