directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r467231 - in /directory: branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/ branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/support/ branches/mina/1.0/core/src/main/java/org/apache/mina/tran...
Date Tue, 24 Oct 2006 03:53:46 GMT
Author: trustin
Date: Mon Oct 23 20:53:45 2006
New Revision: 467231

URL: http://svn.apache.org/viewvc?view=rev&rev=467231
Log:
Fixed issue: DIRMINA-266 (SocketAcceptor.bind() requires address != null and port != 0...
why? Also can get to ServerSocketChannel.socket().getLocalSocketAddress())
* Allowed both null and socket address with port number '0'
* Added a test case for anonymous binds


Modified:
    directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
    directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
    directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
    directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
    directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java
    directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
    directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
    directory/trunks/mina/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java

Modified: directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
(original)
+++ directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
Mon Oct 23 20:53:45 2006
@@ -115,26 +115,16 @@
      */
     public void bind( SocketAddress address, IoHandler handler, IoServiceConfig config )
throws IOException
     {
-        if( address == null )
-        {
-            throw new NullPointerException( "address" );
-        }
-
         if( handler == null )
         {
             throw new NullPointerException( "handler" );
         }
 
-        if( !( address instanceof InetSocketAddress ) )
+        if( address != null && !( address instanceof InetSocketAddress ) )
         {
             throw new IllegalArgumentException( "Unexpected address type: " + address.getClass()
);
         }
 
-        if( ( ( InetSocketAddress ) address ).getPort() == 0 )
-        {
-            throw new IllegalArgumentException( "Unsupported port number: 0" );
-        }
-
         if( config == null )
         {
             config = getDefaultConfig();
@@ -437,6 +427,10 @@
 
                 // and bind.
                 ssc.socket().bind( req.address, cfg.getBacklog() );
+                if( req.address == null || req.address.getPort() == 0 )
+                {
+                    req.address = ( InetSocketAddress ) ssc.socket().getLocalSocketAddress();
+                }
                 ssc.register( selector, SelectionKey.OP_ACCEPT, req );
 
                 synchronized( channels )
@@ -546,7 +540,7 @@
 
     private static class RegistrationRequest
     {
-        private final SocketAddress address;
+        private InetSocketAddress address;
         private final IoHandler handler;
         private final IoServiceConfig config;
         private IOException exception;
@@ -554,7 +548,7 @@
 
         private RegistrationRequest( SocketAddress address, IoHandler handler, IoServiceConfig
config )
         {
-            this.address = address;
+            this.address = ( InetSocketAddress ) address;
             this.handler = handler;
             this.config = config;
         }

Modified: directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
(original)
+++ directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
Mon Oct 23 20:53:45 2006
@@ -83,8 +83,6 @@
     public void bind( SocketAddress address, IoHandler handler, IoServiceConfig config )
             throws IOException
     {
-        if( address == null )
-            throw new NullPointerException( "address" );
         if( handler == null )
             throw new NullPointerException( "handler" );
         if( config == null )
@@ -92,11 +90,9 @@
             config = getDefaultConfig();
         }
 
-        if( !( address instanceof InetSocketAddress ) )
+        if( address != null && !( address instanceof InetSocketAddress ) )
             throw new IllegalArgumentException( "Unexpected address type: "
                                                 + address.getClass() );
-        if( ( ( InetSocketAddress ) address ).getPort() == 0 )
-            throw new IllegalArgumentException( "Unsupported port number: 0" );
         
         RegistrationRequest request = new RegistrationRequest( address, handler, config );
         synchronized( this )
@@ -601,6 +597,10 @@
 
                 ch.configureBlocking( false );
                 ch.socket().bind( req.address );
+                if( req.address == null || req.address.getPort() == 0 )
+                {
+                    req.address = ( InetSocketAddress ) ch.socket().getLocalSocketAddress();
+                }
                 ch.register( selector, SelectionKey.OP_READ, req );
                 synchronized( channels )
                 {
@@ -712,7 +712,7 @@
 
     private static class RegistrationRequest
     {
-        private final SocketAddress address;
+        private InetSocketAddress address;
         private final IoHandler handler;
         private final IoServiceConfig config;
 
@@ -721,7 +721,7 @@
         
         private RegistrationRequest( SocketAddress address, IoHandler handler, IoServiceConfig
config )
         {
-            this.address = address;
+            this.address = ( InetSocketAddress ) address;
             this.handler = handler;
             this.config = config;
         }

Modified: directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
(original)
+++ directory/branches/mina/1.0/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
Mon Oct 23 20:53:45 2006
@@ -57,11 +57,9 @@
 
     public void bind( SocketAddress address, IoHandler handler, IoServiceConfig config )
throws IOException
     {
-        if( address == null )
-            throw new NullPointerException( "address" );
         if( handler == null )
             throw new NullPointerException( "handler" );
-        if( !( address instanceof VmPipeAddress ) )
+        if( address != null && !( address instanceof VmPipeAddress ) )
             throw new IllegalArgumentException(
                     "address must be VmPipeAddress." );
 
@@ -72,7 +70,18 @@
 
         synchronized( boundHandlers )
         {
-            if( boundHandlers.containsKey( address ) )
+            if( address == null || ( ( VmPipeAddress ) address ).getPort() == 0 )
+            {
+                for( int i = 1; i < Integer.MAX_VALUE; i++ )
+                {
+                    address = new VmPipeAddress( i );
+                    if( !boundHandlers.containsKey( address ) )
+                    {
+                        break;
+                    }
+                }
+            }
+            else if( boundHandlers.containsKey( address ) )
             {
                 throw new IOException( "Address already bound: " + address );
             }

Modified: directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
(original)
+++ directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
Mon Oct 23 20:53:45 2006
@@ -56,6 +56,7 @@
     }
     
     protected abstract SocketAddress createSocketAddress( int port );
+    protected abstract int getPort( SocketAddress address );
     
     protected void bind( boolean reuseAddress ) throws IOException
     {
@@ -107,12 +108,28 @@
     {
         try
         {
-            acceptor.unbind( createSocketAddress( port ) );
+            acceptor.unbindAll();
         }
         catch( Exception e )
         {
             // ignore
         }
+    }
+
+    public void testAnonymousBind() throws Exception
+    {
+        acceptor.bind( null, new IoHandlerAdapter() );
+        Assert.assertEquals( 1, acceptor.getManagedServiceAddresses().size() );
+        acceptor.unbindAll();
+        Thread.sleep(500);
+        Assert.assertEquals( 0, acceptor.getManagedServiceAddresses().size() );
+        
+        acceptor.bind( createSocketAddress( 0 ), new IoHandlerAdapter() );
+        Assert.assertEquals( 1, acceptor.getManagedServiceAddresses().size() );
+        SocketAddress address =
+                ( SocketAddress ) acceptor.getManagedServiceAddresses().iterator().next();
+        Assert.assertTrue( getPort( address ) != 0 );
+        acceptor.unbind( address );
     }
     
     public void testDuplicateBind() throws IOException

Modified: directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java
(original)
+++ directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java
Mon Oct 23 20:53:45 2006
@@ -42,4 +42,9 @@
     {
         return new InetSocketAddress( port );
     }    
+
+    protected int getPort( SocketAddress address )
+    {
+        return ( ( InetSocketAddress ) address ).getPort();
+    }
 }

Modified: directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
(original)
+++ directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
Mon Oct 23 20:53:45 2006
@@ -50,6 +50,11 @@
         return new InetSocketAddress( port );
     }
     
+    protected int getPort( SocketAddress address )
+    {
+        return ( ( InetSocketAddress ) address ).getPort();
+    }
+
     public void testUnbindDisconnectsClients() throws Exception
     {
         // TODO: This test is almost identical to the test with the same name in VmPipeBindTest

Modified: directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java
URL: http://svn.apache.org/viewvc/directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java
(original)
+++ directory/branches/mina/1.0/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java
Mon Oct 23 20:53:45 2006
@@ -49,6 +49,11 @@
         return new VmPipeAddress( port );
     }
     
+    protected int getPort( SocketAddress address )
+    {
+        return ( ( VmPipeAddress ) address ).getPort();
+    }
+
     public void testUnbindDisconnectsClients() throws Exception
     {
         // TODO: This test is almost identical to the test with the same name in SocketBindTest

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/common/support/BaseIoAcceptor.java
Mon Oct 23 20:53:45 2006
@@ -54,12 +54,7 @@
     
     public void setLocalAddress( SocketAddress localAddress )
     {
-        if( localAddress == null )
-        {
-            throw new NullPointerException( "localAddress" );
-        }
-        
-        if( !getAddressType().isAssignableFrom( localAddress.getClass() ) )
+        if( localAddress != null && !getAddressType().isAssignableFrom( localAddress.getClass()
) )
         {
             throw new IllegalArgumentException(
                     "localAddress type: " + localAddress.getClass() + 
@@ -95,11 +90,6 @@
             if( bound )
             {
                 throw new IllegalStateException( "Already bound to: " + getLocalAddress()
);
-            }
-            
-            if( getLocalAddress() == null )
-            {
-                throw new IllegalStateException( "localAddress is not set." );
             }
             
             if( getHandler() == null )

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java
Mon Oct 23 20:53:45 2006
@@ -193,11 +193,6 @@
     
     protected void doBind() throws IOException
     {
-        if( ( ( InetSocketAddress ) getLocalAddress() ).getPort() == 0 )
-        {
-            throw new IllegalStateException( "Unsupported port number: 0" );
-        }
-
         RegistrationRequest request = new RegistrationRequest();
 
         synchronized( registerQueue )
@@ -226,7 +221,7 @@
 
         if( request.exception != null )
         {
-            // TODO better excaption handling.
+            // TODO better exception handling.
             if( request.exception instanceof RuntimeException )
             {
                 throw ( RuntimeException ) request.exception;
@@ -239,6 +234,13 @@
             {
                 throw new RuntimeIOException( request.exception );
             }
+        }
+        else
+        {
+            // Update the local address.
+            // setLocalAddress() shouldn't be called from the worker thread
+            // because of deadlock.
+            setLocalAddress(serverSocketChannel.socket().getLocalSocketAddress());
         }
     }
 

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
Mon Oct 23 20:53:45 2006
@@ -25,9 +25,7 @@
 import java.nio.channels.DatagramChannel;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
-import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.mina.common.ByteBuffer;
@@ -65,7 +63,7 @@
     private final Executor executor;
     private final int id = nextId ++ ;
     private Selector selector;
-    private final Map channels = new HashMap();
+    private DatagramChannel channel;
     private final Queue registerQueue = new Queue();
     private final Queue cancelQueue = new Queue();
     private final Queue flushingSessions = new Queue();
@@ -87,9 +85,6 @@
 
     protected void doBind() throws IOException
     {
-        if( ( ( InetSocketAddress ) getLocalAddress() ).getPort() == 0 )
-            throw new IllegalArgumentException( "Unsupported port number: 0" );
-        
         RegistrationRequest request = new RegistrationRequest();
         synchronized( this )
         {
@@ -119,6 +114,10 @@
         {
             throw ( IOException ) new IOException( "Failed to bind" ).initCause( request.exception
);
         }
+        else
+        {
+            setLocalAddress( channel.socket().getLocalSocketAddress() );
+        }
     }
 
     protected void doUnbind()
@@ -172,23 +171,23 @@
         {
             throw new NullPointerException( "remoteAddress" );
         }
-        if( getLocalAddress() == null )
-        {
-            throw new NullPointerException( "localAddress" );
-        }
         
-        Selector selector = this.selector;
-        DatagramChannel ch = ( DatagramChannel ) channels.get( getLocalAddress() );
-        if( selector == null || ch == null )
+        synchronized( bindLock )
         {
-            throw new IllegalArgumentException( "Unknown localAddress: " + getLocalAddress()
);
+            if( !isBound() )
+            {
+                throw new IllegalStateException( "Can't create a session from a unbound service."
);
+            }
+         
+            return newSessionWithoutLock( remoteAddress );
         }
-            
+    }
+    
+    private IoSession newSessionWithoutLock( SocketAddress remoteAddress )
+    {
+        Selector selector = this.selector;
+        DatagramChannel ch = this.channel;
         SelectionKey key = ch.keyFor( selector );
-        if( key == null )
-        {
-            throw new IllegalArgumentException( "Unknown localAddress: " + getLocalAddress()
);
-        }
 
         IoSession session;
         IoSessionRecycler sessionRecycler = getSessionRecycler();
@@ -402,7 +401,7 @@
             if( remoteAddress != null )
             {
                 DatagramSessionImpl session =
-                    ( DatagramSessionImpl ) newSession( remoteAddress );
+                    ( DatagramSessionImpl ) newSessionWithoutLock( remoteAddress );
 
                 readBuf.flip();
 
@@ -557,10 +556,7 @@
                 ch.configureBlocking( false );
                 ch.socket().bind( getLocalAddress() );
                 ch.register( selector, SelectionKey.OP_READ, req );
-                synchronized( channels )
-                {
-                    channels.put( getLocalAddress(), ch );
-                }
+                this.channel = ch;
                 
                 getListeners().fireServiceActivated();
             }
@@ -610,28 +606,17 @@
                 break;
             }
 
-            DatagramChannel ch;
-            synchronized( channels )
-            {
-                ch = ( DatagramChannel ) channels.remove( getLocalAddress() );
-            }
+            DatagramChannel ch = this.channel;
+            this.channel = null;
 
             // close the channel
             try
             {
-                if( ch == null )
-                {
-                    request.exception = new IllegalArgumentException(
-                            "Address not bound: " + getLocalAddress() );
-                }
-                else
-                {
-                    SelectionKey key = ch.keyFor( selector );
-                    key.cancel();
-                    selector.wakeup(); // wake up again to trigger thread death
-                    ch.disconnect();
-                    ch.close();
-                }
+                SelectionKey key = ch.keyFor( selector );
+                key.cancel();
+                selector.wakeup(); // wake up again to trigger thread death
+                ch.disconnect();
+                ch.close();
             }
             catch( Throwable t )
             {

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
Mon Oct 23 20:53:45 2006
@@ -58,19 +58,32 @@
 
     protected void doBind() throws IOException
     {
+        VmPipeAddress localAddress = ( VmPipeAddress ) getLocalAddress();
+        
         synchronized( boundHandlers )
         {
-            if( boundHandlers.containsKey( getLocalAddress() ) )
+            if( localAddress == null || localAddress.getPort() == 0 )
+            {
+                for( int i = 1; i < Integer.MAX_VALUE; i++ )
+                {
+                    localAddress = new VmPipeAddress( i );
+                    if( !boundHandlers.containsKey( localAddress ) )
+                    {
+                        break;
+                    }
+                }
+            }
+            else if( boundHandlers.containsKey( localAddress ) )
             {
-                throw new IOException( "Address already bound: " + getLocalAddress() );
+                throw new IOException( "Address already bound: " + localAddress );
             }
 
-            boundHandlers.put( getLocalAddress(), 
-                               new VmPipe( this,
-                                          ( VmPipeAddress ) getLocalAddress(),
-                                          getHandler(), getListeners() ) );
+            boundHandlers.put(
+                    localAddress, 
+                    new VmPipe( this, localAddress, getHandler(), getListeners() ) );
         }
         
+        setLocalAddress( localAddress );
         getListeners().fireServiceActivated();
     }
     

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/transport/AbstractBindTest.java
Mon Oct 23 20:53:45 2006
@@ -55,6 +55,7 @@
     }
     
     protected abstract SocketAddress createSocketAddress( int port );
+    protected abstract int getPort( SocketAddress address );
     
     protected void bind( boolean reuseAddress ) throws IOException
     {
@@ -114,6 +115,21 @@
         {
             // ignore
         }
+        
+        acceptor.setLocalAddress( null );
+    }
+    
+    public void testAnonymousBind() throws Exception
+    {
+        acceptor.setHandler( new IoHandlerAdapter() );
+        acceptor.setLocalAddress( null );
+        acceptor.bind();
+        Assert.assertNotNull( acceptor.getLocalAddress() );
+        acceptor.unbind();
+        acceptor.setLocalAddress( createSocketAddress( 0 ) );
+        Assert.assertNotNull( acceptor.getLocalAddress() );
+        Assert.assertTrue( getPort( acceptor.getLocalAddress() ) != 0 );
+        acceptor.unbind();
     }
     
     public void testDuplicateBind() throws IOException

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/DatagramBindTest.java
Mon Oct 23 20:53:45 2006
@@ -41,5 +41,10 @@
     protected SocketAddress createSocketAddress( int port )
     {
         return new InetSocketAddress( port );
-    }    
+    }
+    
+    protected int getPort( SocketAddress address )
+    {
+        return ( ( InetSocketAddress ) address ).getPort();
+    }
 }

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/transport/socket/nio/SocketBindTest.java
Mon Oct 23 20:53:45 2006
@@ -50,6 +50,11 @@
         return new InetSocketAddress( port );
     }
     
+    protected int getPort( SocketAddress address )
+    {
+        return ( ( InetSocketAddress ) address ).getPort();
+    }
+
     public void testUnbindDisconnectsClients() throws Exception
     {
         // TODO: This test is almost identical to the test with the same name in VmPipeBindTest

Modified: directory/trunks/mina/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java?view=diff&rev=467231&r1=467230&r2=467231
==============================================================================
--- directory/trunks/mina/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java
(original)
+++ directory/trunks/mina/core/src/test/java/org/apache/mina/transport/vmpipe/VmPipeBindTest.java
Mon Oct 23 20:53:45 2006
@@ -49,6 +49,11 @@
         return new VmPipeAddress( port );
     }
     
+    protected int getPort( SocketAddress address )
+    {
+        return ( ( VmPipeAddress ) address ).getPort();
+    }
+    
     public void testUnbindDisconnectsClients() throws Exception
     {
         // TODO: This test is almost identical to the test with the same name in SocketBindTest



Mime
View raw message