directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r164313 - in /directory/network/trunk/src: java/org/apache/mina/common/ java/org/apache/mina/io/datagram/ java/org/apache/mina/io/filter/ java/org/apache/mina/io/socket/ java/org/apache/mina/protocol/io/ java/org/apache/mina/protocol/vmpipe/ java/org/apache/mina/util/ test/org/apache/mina/examples/echoserver/ test/org/apache/mina/io/ test/org/apache/mina/protocol/ test/org/apache/mina/protocol/codec/
Date Sat, 23 Apr 2005 01:54:03 GMT
Author: trustin
Date: Fri Apr 22 18:54:01 2005
New Revision: 164313

URL: http://svn.apache.org/viewcvs?rev=164313&view=rev
Log:
* Merged Vinod's patch with a little modification.
* Added Session.close( boolean wait ) for users who want to close synchronously.

Modified:
    directory/network/trunk/src/java/org/apache/mina/common/Session.java
    directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java
    directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java
    directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
    directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
    directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
    directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java
    directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
    directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
    directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java
    directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java
    directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java

Modified: directory/network/trunk/src/java/org/apache/mina/common/Session.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/common/Session.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/common/Session.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/common/Session.java Fri Apr 22 18:54:01
2005
@@ -36,9 +36,18 @@
 public interface Session {
 
     /**
-     * Closes this session immediately.
+     * Closes this session immediately.  Calling method is identical with
+     * calling <tt>close( false )</tt>.
      */
     void close();
+
+    /**
+     * Closes this session immediately.
+     * 
+     * @param wait <tt>true</tt> if you want to wait for closing process is
+     *             complete.
+     */
+    void close( boolean wait );
     
     /**
      * Returns an attachment of this session.

Modified: directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/datagram/DatagramSession.java Fri
Apr 22 18:54:01 2005
@@ -55,6 +55,8 @@
     private SocketAddress remoteAddress;
 
     private SelectionKey key;
+    
+    private boolean disposed;
 
     /**
      * Creates a new instance.
@@ -96,12 +98,39 @@
     {
         return handler;
     }
+    
+    synchronized void notifyClose()
+    {
+        if( !disposed )
+        {
+            disposed = true;
+            notify();
+        }
+    }
 
-    public void close()
+    public synchronized void close( boolean wait )
     {
+        if( disposed )
+        {
+            return;
+        }
+
         if( filters.processor instanceof DatagramConnector )
         {
             filters.processor.closeSession( this );
+            if( wait )
+            {
+                while( disposed )
+                {
+                    try
+                    {
+                        wait();
+                    }
+                    catch( InterruptedException e )
+                    {
+                    }
+                }
+            }
         }
     }
 

Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java Fri Apr 22 18:54:01
2005
@@ -31,6 +31,7 @@
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.DefaultExceptionMonitor;
+import org.apache.mina.io.IoHandler;
 import org.apache.mina.io.IoHandlerFilterAdapter;
 import org.apache.mina.io.IoSession;
 
@@ -49,6 +50,18 @@
  */
 public class SSLFilter extends IoHandlerFilterAdapter
 {
+    /**
+     * A marker which is passed with {@link IoHandler#dataWritten(IoSession, Object)}
+     * when <tt>SSLFilter</tt> writes data other then user actually requested.
+     */
+    public static final Object SSL_MARKER = new Object()
+    {
+        public String toString()
+        {
+            return "SSL_MARKER";
+        }
+    };
+    
     // SSL Context
     private SSLContext sslContext;
 
@@ -58,6 +71,12 @@
     /** debug interface */
     Debug debug = null;
 
+    private boolean client;
+    private boolean needClientAuth;
+    private boolean wantClientAuth;
+    private String[] enabledCipherSuites;
+    private String[] enabledProtocols;
+
     /**
      * Creates a new SSL filter using the specified {@link SSLContext}.
      */
@@ -72,6 +91,104 @@
     }
 
     /**
+     * Returns <tt>true</tt> if the engine is set to use client mode
+     * when handshaking.
+     */
+    public boolean isUseClientMode()
+    {
+        return client;
+    }
+    
+    /**
+     * Configures the engine to use client (or server) mode when handshaking.
+     */
+    public void setUseClientMode( boolean clientMode )
+    {
+        this.client = clientMode;
+    }
+    
+    /**
+     * Returns <tt>true</tt> if the engine will <em>require</em>
client authentication.
+     * This option is only useful to engines in the server mode.
+     */
+    public boolean isNeedClientAuth()
+    {
+        return needClientAuth;
+    }
+
+    /**
+     * Configures the engine to <em>require</em> client authentication.
+     * This option is only useful for engines in the server mode.
+     */
+    public void setNeedClientAuth( boolean needClientAuth )
+    {
+        this.needClientAuth = needClientAuth;
+    }
+    
+    
+    /**
+     * Returns <tt>true</tt> if the engine will <em>request</em>
client authentication.
+     * This option is only useful to engines in the server mode.
+     */
+    public boolean isWantClientAuth()
+    {
+        return wantClientAuth;
+    }
+    
+    /**
+     * Configures the engine to <em>request</em> client authentication.
+     * This option is only useful for engines in the server mode.
+     */
+    public void setWantClientAuth( boolean wantClientAuth )
+    {
+        this.wantClientAuth = wantClientAuth;
+    }
+    
+    /**
+     * Returns the list of cipher suites to be enabled when {@link SSLEngine}
+     * is initialized.
+     * 
+     * @return <tt>null</tt> means 'use {@link SSLEngine}'s default.'
+     */
+    public String[] getEnabledCipherSuites()
+    {
+        return enabledCipherSuites;
+    }
+    
+    /**
+     * Sets the list of cipher suites to be enabled when {@link SSLEngine}
+     * is initialized.
+     * 
+     * @param cipherSuites <tt>null</tt> means 'use {@link SSLEngine}'s default.'
+     */
+    public void setEnabledCipherSuites( String[] cipherSuites )
+    {
+        this.enabledCipherSuites = cipherSuites;
+    }
+
+    /**
+     * Returns the list of protocols to be enabled when {@link SSLEngine}
+     * is initialized.
+     * 
+     * @return <tt>null</tt> means 'use {@link SSLEngine}'s default.'
+     */
+    public String[] getEnabledProtocols()
+    {
+        return enabledProtocols;
+    }
+    
+    /**
+     * Sets the list of protocols to be enabled when {@link SSLEngine}
+     * is initialized.
+     * 
+     * @param protocols <tt>null</tt> means 'use {@link SSLEngine}'s default.'
+     */
+    public void setEnabledProtocols( String[] protocols )
+    {
+        this.enabledProtocols = protocols;
+    }
+
+    /**
      * Sets the debug message auditter.
      */
     public void setDebug( Debug debug )
@@ -110,9 +227,12 @@
 
     public void sessionOpened( NextFilter nextFilter, IoSession session )
     {
-        nextFilter.sessionOpened( session );
         // Create an SSL handler
-        createSSLSessionHandler( session );
+        if( createSSLSessionHandler( session ) == null )
+        {
+            throw new InternalError();
+        }
+        nextFilter.sessionOpened( session );
     }
 
     public void sessionClosed( NextFilter nextFilter, IoSession session )
@@ -120,7 +240,7 @@
         SSLHandler sslHandler = getSSLSessionHandler( session );
         if( debug != null )
         {
-            debug.print( "Closed: " + sslHandler );
+            debug.print( this, "Closed: " + sslHandler );
         }
         if( sslHandler != null )
         {
@@ -160,7 +280,7 @@
         {
             if( debug != null )
             {
-                debug.print( "Data Read: " + sslHandler + " (" + buf+ ')' );
+                debug.print( this, "Data Read: " + sslHandler + " (" + buf+ ')' );
             }
             synchronized( sslHandler )
             {
@@ -176,8 +296,9 @@
                     {
                         if( debug != null )
                         {
-                            debug
-                                    .print( "SSL Session closed. Closing connection.." );
+                            debug.print(
+                                    this,
+                                    "SSL Session closed. Closing connection.." );
                         }
                         session.close();
                     }
@@ -214,8 +335,9 @@
         SSLHandler sslHandler = getSSLSessionHandler( session );
         if( debug != null )
         {
-            debug.print( "Filtered Write: " + sslHandler );
+            debug.print( this, "Filtered Write: " + sslHandler );
         }
+
         if( sslHandler != null )
         {
             synchronized( sslHandler )
@@ -225,7 +347,7 @@
                     // data already encrypted; simply return buffer
                     if( debug != null )
                     {
-                        debug.print( "  already encrypted: " + buf );
+                        debug.print( this, "  already encrypted: " + buf );
                     }
                     nextFilter.filterWrite( session, buf, marker );
                     return;
@@ -237,7 +359,7 @@
                     {
                         if( debug != null )
                         {
-                            debug.print( "encrypt: " + buf );
+                            debug.print( this, "encrypt: " + buf );
                         }
                         sslHandler.encrypt( buf.buf() );
                         ByteBuffer encryptedBuffer = copy( sslHandler
@@ -245,7 +367,7 @@
 
                         if( debug != null )
                         {
-                            debug.print( "encrypted buf: " + encryptedBuffer);
+                            debug.print( this, "encrypted buf: " + encryptedBuffer);
                         }
                         buf.release();
                         nextFilter.filterWrite( session, encryptedBuffer, marker );
@@ -279,7 +401,7 @@
     {
         if( debug != null )
         {
-            debug.print( "appBuffer: " + sslHandler.getAppBuffer() );
+            debug.print( this, "appBuffer: " + sslHandler.getAppBuffer() );
         }
         if( sslHandler.getAppBuffer().hasRemaining() )
         {
@@ -287,19 +409,23 @@
             ByteBuffer readBuffer = copy( sslHandler.getAppBuffer() );
             if( debug != null )
             {
-                debug.print( "app data read: " + readBuffer + " (" + readBuffer.getHexDump()
+ ')' );
+                debug.print( this, "app data read: " + readBuffer + " (" + readBuffer.getHexDump()
+ ')' );
             }
             nextFilter.dataRead( session, readBuffer );
         }
     }
 
-    private void writeNetBuffer( IoSession session, SSLHandler sslHandler )
+    void writeNetBuffer( IoSession session, SSLHandler sslHandler )
             throws SSLException
     {
         // first check if any net data needed to be writen
         if( !sslHandler.getOutNetBuffer().hasRemaining() )
         {
             // no; bail out
+            if( debug != null )
+            {
+                debug.print( this, "net data is empty" );
+            }
             return;
         }
 
@@ -316,16 +442,16 @@
         {
             if( debug != null )
             {
-                debug.print( "write outNetBuffer: "
-                        + sslHandler.getOutNetBuffer() );
+                debug.print( this, "write outNetBuffer: " +
+                                   sslHandler.getOutNetBuffer() );
             }
             ByteBuffer writeBuffer = copy( sslHandler.getOutNetBuffer() );
             if( debug != null )
             {
-                debug.print( "session write: " + writeBuffer );
+                debug.print( this, "session write: " + writeBuffer );
             }
             //debug("outNetBuffer (after copy): {0}", sslHandler.getOutNetBuffer());
-            session.write( writeBuffer, null );
+            session.write( writeBuffer, SSL_MARKER );
 
             // loop while more writes required to complete handshake
             while( sslHandler.needToCompleteInitialHandshake() )
@@ -345,12 +471,12 @@
                 {
                     if( debug != null )
                     {
-                        debug.print( "write outNetBuffer2: "
-                                + sslHandler.getOutNetBuffer() );
+                        debug.print( this, "write outNetBuffer2: " +
+                                           sslHandler.getOutNetBuffer() );
                     }
                     ByteBuffer writeBuffer2 = copy( sslHandler
                             .getOutNetBuffer() );
-                    session.write( writeBuffer2, null );
+                    session.write( writeBuffer2, SSL_MARKER );
                 }
             }
         }
@@ -382,12 +508,35 @@
 
     private SSLHandler createSSLSessionHandler( IoSession session )
     {
-        SSLHandler sslHandler = new SSLHandler( this, sslContext );
-        synchronized( sslSessionHandlerMap )
+        SSLHandler handler = ( SSLHandler ) sslSessionHandlerMap.get( session );
+        if( handler == null )
         {
-            sslSessionHandlerMap.put( session, sslHandler );
+            synchronized( sslSessionHandlerMap )
+            {
+                handler = ( SSLHandler ) sslSessionHandlerMap.get( session );
+                if( handler == null )
+                {
+                    try
+                    {
+                        handler =
+                            new SSLHandler( this, sslContext, session );
+                        sslSessionHandlerMap.put( session, handler );
+                        if( isUseClientMode() )
+                        {
+                            handler.doHandshake();
+                        }
+                    }
+                    catch( SSLException e )
+                    {
+                        sslSessionHandlerMap.remove( session );
+                        throw new RuntimeException(
+                                "Failed to initialize SSLEngine.", e );
+                    }
+                }
+            }
         }
-        return sslHandler;
+        
+        return handler;
     }
 
     private SSLHandler getSSLSessionHandler( IoSession session )
@@ -424,7 +573,7 @@
         /**
          * Prints out the specified debug messages.
          */
-        void print( String message );
+        void print( SSLFilter filter, String message );
     }
 
     private static class DebugOn implements Debug
@@ -467,8 +616,17 @@
 
         private final Date date = new Date();
 
-        public void print( String message )
+        public void print( SSLFilter filter, String message )
         {
+            if( filter.isUseClientMode() )
+            {
+                message = "[CLIENT] " + message;
+            }
+            else
+            {
+                message = "[SERVER] " + message;
+            }
+
             if( log == null )
             {
                 logToStdOut( message );
@@ -509,7 +667,7 @@
 
     private static class DebugOff implements Debug
     {
-        public void print( String message )
+        public void print( SSLFilter filter, String message )
         {
             // do nothing
         }

Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java Fri Apr 22
18:54:01 2005
@@ -24,6 +24,8 @@
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLEngineResult;
 import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+import org.apache.mina.io.IoSession;
 
 /**
  * A helper class using the SSLEngine API to decrypt/encrypt data.
@@ -60,7 +62,7 @@
     /**
      * Empty buffer used during initial handshake and close operations
      */
-    private static ByteBuffer hsBB = ByteBuffer.allocate( 0 );
+    private ByteBuffer hsBB = ByteBuffer.allocate( 0 );
 
     /**
      * Handshake status
@@ -81,20 +83,38 @@
     private boolean closed = false;
 
     private boolean isWritingEncryptedData = false;
+    private IoSession session = null;
 
     /**
      * Constuctor.
      *
      * @param sslc
+     * @throws SSLException 
      */
-    protected SSLHandler( SSLFilter parent, SSLContext sslc )
+    SSLHandler( SSLFilter parent, SSLContext sslc, IoSession session ) throws SSLException
     {
         this.parent = parent;
+        this.session = session;
         sslEngine = sslc.createSSLEngine();
-        sslEngine.setUseClientMode( false );
-        initialHandshakeStatus = SSLEngineResult.HandshakeStatus.NEED_UNWRAP;
-        initialHandshakeComplete = false;
+        sslEngine.setUseClientMode( parent.isUseClientMode() );
+        sslEngine.setNeedClientAuth( parent.isNeedClientAuth() );
+        sslEngine.setWantClientAuth( parent.isWantClientAuth() );
+  
+        if( parent.getEnabledCipherSuites() != null )
+        {
+            sslEngine.setEnabledCipherSuites( parent.getEnabledCipherSuites() );
+        }
+        
+        if( parent.getEnabledProtocols() != null )
+        {
+            sslEngine.setEnabledProtocols( parent.getEnabledProtocols() );
+        }
 
+        sslEngine.beginHandshake();   
+        initialHandshakeStatus = sslEngine.getHandshakeStatus();//SSLEngineResult.HandshakeStatus.NEED_UNWRAP;
+        initialHandshakeComplete = false;
+        //SSLSession sslSession = sslEngine.getSession
+        
         SSLByteBufferPool.initiate( sslEngine );
 
         appBuffer = SSLByteBufferPool.getApplicationBuffer();
@@ -166,8 +186,10 @@
             appBuffer.limit( 0 );
             if( parent.debug != null )
             {
-                parent.debug.print("expanded inNetBuffer:" + inNetBuffer);
-                parent.debug.print("expanded appBuffer:" + appBuffer);
+                parent.debug.print( parent,
+                                    "expanded inNetBuffer:" + inNetBuffer );
+                parent.debug.print( parent, 
+                                    "expanded appBuffer:" + appBuffer );
             }
         }
 
@@ -192,7 +214,7 @@
     {
         if( parent.debug != null )
         {
-            parent.debug.print( "continueHandshake()" );
+            parent.debug.print( parent, "continueHandshake()" );
         }
         doHandshake();
     }
@@ -267,7 +289,7 @@
         if( appBuffer.hasRemaining() )
         {
              if ( parent.debug != null ) {
-                 parent.debug.print( "Error: appBuffer not empty!" );
+                 parent.debug.print( parent, "Error: appBuffer not empty!" );
              }
             //still app data in buffer!?
             throw new IllegalStateException();
@@ -316,13 +338,13 @@
                 // shouln't need to be larger than twice the source data size?
                 outNetBuffer = SSLByteBufferPool.expandBuffer( outNetBuffer, src.capacity()
* 2 );
                 if ( parent.debug != null ) {
-                    parent.debug.print( "expanded outNetBuffer:" + outNetBuffer );
+                    parent.debug.print( parent, "expanded outNetBuffer:" + outNetBuffer );
                 }
             }
 
             result = sslEngine.wrap( src, outNetBuffer );
             if ( parent.debug != null ) {
-                parent.debug.print( "Wrap res:" + result );
+                parent.debug.print( parent, "Wrap res:" + result );
             }
 
             if ( result.getStatus() == SSLEngineResult.Status.OK ) {
@@ -347,15 +369,18 @@
 
         if( parent.debug != null )
         {
-            parent.debug.print( "doHandshake()" );
+            parent.debug.print( parent, "doHandshake()" );
         }
+
         while( true )
         {
             if( initialHandshakeStatus == SSLEngineResult.HandshakeStatus.FINISHED )
             {
                 if( parent.debug != null )
                 {
-                    parent.debug.print( " initialHandshakeStatus=FINISHED" );
+                    SSLSession sslSession = sslEngine.getSession();
+                    parent.debug.print( parent, " initialHandshakeStatus=FINISHED" );
+                    parent.debug.print( parent, " sslSession CipherSuite used " + sslSession.getCipherSuite());
                 }
                 initialHandshakeComplete = true;
                 return;
@@ -364,7 +389,7 @@
             {
                 if( parent.debug != null )
                 {
-                    parent.debug.print( " initialHandshakeStatus=NEED_TASK" );
+                    parent.debug.print( parent, " initialHandshakeStatus=NEED_TASK" );
                 }
                 initialHandshakeStatus = doTasks();
             }
@@ -373,8 +398,9 @@
                 // we need more data read
                 if( parent.debug != null )
                 {
-                    parent.debug
-                            .print( " initialHandshakeStatus=NEED_UNWRAP" );
+                    parent.debug.print(
+                            parent,
+                            " initialHandshakeStatus=NEED_UNWRAP" );
                 }
                 SSLEngineResult.Status status = unwrapHandshake();
                 if( status == SSLEngineResult.Status.BUFFER_UNDERFLOW
@@ -388,7 +414,7 @@
             {
                 if( parent.debug != null )
                 {
-                    parent.debug.print( " initialHandshakeStatus=NEED_WRAP" );
+                    parent.debug.print( parent, " initialHandshakeStatus=NEED_WRAP" );
                 }
                 // First make sure that the out buffer is completely empty. Since we
                 // cannot call wrap with data left on the buffer
@@ -396,7 +422,7 @@
                 {
                     if( parent.debug != null )
                     {
-                        parent.debug.print( " Still data in out buffer!" );
+                        parent.debug.print( parent, " Still data in out buffer!" );
                     }
                     return;
                 }
@@ -404,11 +430,12 @@
                 SSLEngineResult result = sslEngine.wrap( hsBB, outNetBuffer );
                 if( parent.debug != null )
                 {
-                    parent.debug.print( "Wrap res:" + result );
+                    parent.debug.print( parent, "Wrap res:" + result );
                 }
 
                 outNetBuffer.flip();
                 initialHandshakeStatus = result.getHandshakeStatus();
+                parent.writeNetBuffer( session, this );
                 // return to allow data on out buffer being sent
                 // TODO: We might want to send more data immidiatley?
             }
@@ -424,7 +451,7 @@
     {
         if( parent.debug != null )
         {
-            parent.debug.print( "unwrap()" );
+            parent.debug.print( parent, "unwrap()" );
         }
         // Prepare the application buffer to receive decrypted data
         appBuffer.clear();
@@ -437,13 +464,13 @@
         {
             if( parent.debug != null )
             {
-                parent.debug.print( "  inNetBuffer: " + inNetBuffer );
-                parent.debug.print( "  appBuffer: " + appBuffer );
+                parent.debug.print( parent, "  inNetBuffer: " + inNetBuffer );
+                parent.debug.print( parent, "  appBuffer: " + appBuffer );
             }
             res = sslEngine.unwrap( inNetBuffer, appBuffer );
             if( parent.debug != null )
             {
-                parent.debug.print( "Unwrap res:" + res );
+                parent.debug.print( parent, "Unwrap res:" + res );
             }
         }
         while( res.getStatus() == SSLEngineResult.Status.OK );
@@ -470,11 +497,11 @@
         return checkStatus( res.getStatus() );
     }
 
-    SSLEngineResult.Status unwrapHandshake() throws SSLException
+    private SSLEngineResult.Status unwrapHandshake() throws SSLException
     {
         if( parent.debug != null )
         {
-            parent.debug.print( "unwrapHandshake()" );
+            parent.debug.print( parent, "unwrapHandshake()" );
         }
         // Prepare the application buffer to receive decrypted data
         appBuffer.clear();
@@ -487,13 +514,13 @@
         {
             if( parent.debug != null )
             {
-                parent.debug.print( "  inNetBuffer: " + inNetBuffer );
-                parent.debug.print( "  appBuffer: " + appBuffer );
+                parent.debug.print( parent, "  inNetBuffer: " + inNetBuffer );
+                parent.debug.print( parent, "  appBuffer: " + appBuffer );
             }
             res = sslEngine.unwrap( inNetBuffer, appBuffer );
             if( parent.debug != null )
             {
-                parent.debug.print( "Unwrap res:" + res );
+                parent.debug.print( parent, "Unwrap res:" + res );
             }
 
         }
@@ -531,7 +558,7 @@
     {
         if( parent.debug != null )
         {
-            parent.debug.print( "  doTasks()" );
+            parent.debug.print( parent, "  doTasks()" );
         }
 
         /*
@@ -543,13 +570,13 @@
         {
             if( parent.debug != null )
             {
-                parent.debug.print( "   doTask: " + runnable );
+                parent.debug.print( parent, "   doTask: " + runnable );
             }
             runnable.run();
         }
         if( parent.debug != null )
         {
-            parent.debug.print( "  doTasks(): "
+            parent.debug.print( parent, "  doTasks(): "
                     + sslEngine.getHandshakeStatus() );
         }
         return sslEngine.getHandshakeStatus();

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketIoProcessor.java Fri
Apr 22 18:54:01 2005
@@ -202,6 +202,7 @@
             finally
             {
                 session.getFilters().sessionClosed( session );
+                session.notifyClose();
             }
         }
     }

Modified: directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/socket/SocketSession.java Fri Apr
22 18:54:01 2005
@@ -55,6 +55,8 @@
     private final SocketAddress localAddress;
 
     private SelectionKey key;
+    
+    private boolean disposed;
 
     /**
      * Creates a new instance.
@@ -96,10 +98,38 @@
     {
         return handler;
     }
+    
+    synchronized void notifyClose()
+    {
+        if( !disposed )
+        {
+            disposed = true;
+            notify();
+        }
+    }
+    
 
-    public void close()
+    public synchronized void close( boolean wait )
     {
+        if( disposed )
+        {
+            return;
+        }
+
         SocketIoProcessor.getInstance().removeSession( this );
+        if( wait )
+        {
+            while( disposed )
+            {
+                try
+                {
+                    wait();
+                }
+                catch( InterruptedException e )
+                {
+                }
+            }
+        }
     }
 
     Queue getWriteBufferQueue()

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/io/IoAdapter.java Fri Apr 22
18:54:01 2005
@@ -277,6 +277,11 @@
         {
             session.close();
         }
+        
+        public void close( boolean wait )
+        {
+            session.close( wait );
+        }
 
         public Object getAttachment()
         {

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/vmpipe/VmPipeSession.java Fri
Apr 22 18:54:01 2005
@@ -110,7 +110,7 @@
         return null;
     }
 
-    public void close()
+    public void close( boolean wait )
     {
         synchronized( lock )
         {

Modified: directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/BaseSession.java Fri Apr 22 18:54:01
2005
@@ -53,6 +53,11 @@
     protected BaseSession()
     {
     }
+    
+    public void close()
+    {
+        this.close( false );
+    }
 
     public Object getAttachment()
     {

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
Fri Apr 22 18:54:01 2005
@@ -57,7 +57,8 @@
     public void testTCPWithSSL() throws Exception
     {
         // Add an SSL filter
-        SSLFilter sslFilter = new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
+        SSLFilter sslFilter =
+            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
         sslFilter.setDebug( SSLFilter.Debug.ON );
         acceptor.getFilterChain().addLast( "SSL", sslFilter );
         

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
Fri Apr 22 18:54:01 2005
@@ -70,10 +70,12 @@
     /**
      * Client-side SSL doesn't work for now.
      */
-    public void _testTCPWithSSL() throws Exception
+    public void testTCPWithSSL() throws Exception
     {
         // Add an SSL filter to acceptor
-        SSLFilter acceptorSSLFilter = new SSLFilter( BogusSSLContextFactory.getInstance(
true ) );
+        SSLFilter acceptorSSLFilter =
+            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
+        acceptorSSLFilter.setDebug( SSLFilter.Debug.ON );
         acceptor.getFilterChain().addLast( "SSL", acceptorSSLFilter );
 
         // Create a connector
@@ -81,7 +83,9 @@
         connector.getFilterChain().addFirst( "threadPool", super.threadPoolFilter );
         
         // Add an SSL filter to connector
-        SSLFilter connectorSSLFilter = new SSLFilter( BogusSSLContextFactory.getInstance(
false ) );
+        SSLFilter connectorSSLFilter =
+            new SSLFilter( BogusSSLContextFactory.getInstance( false ) );
+        connectorSSLFilter.setUseClientMode( true ); // set client mode
         connectorSSLFilter.setDebug( SSLFilter.Debug.ON );
         connector.getFilterChain().addLast( "SSL", connectorSSLFilter );
 
@@ -103,10 +107,10 @@
         System.out.println("* Without localAddress and initializer");
         testConnector( connector, null, null );
         
-        marker = new MarkingInitializer();
-        System.out.println("* Without localAddress and with initializer");
-        testConnector( connector, null, marker );
-        Assert.assertTrue( marker.executed );
+//        marker = new MarkingInitializer();
+//        System.out.println("* Without localAddress and with initializer");
+//        testConnector( connector, null, marker );
+//        Assert.assertTrue( marker.executed );
 
         if( !(connector instanceof SocketConnector) )
         {
@@ -203,16 +207,19 @@
         
         public void dataWritten( IoSession session, Object marker )
         {
-            if( ( counter & 1 ) == 0 )
+            if( marker != SSLFilter.SSL_MARKER )
             {
-                Assert.assertEquals( new Integer( counter ), marker );
-            }
-            else
-            {
-                Assert.assertNull( marker );
+                if( ( counter & 1 ) == 0 )
+                {
+                    Assert.assertEquals( new Integer( counter ), marker );
+                }
+                else
+                {
+                    Assert.assertNull( marker );
+                }
+                
+                counter ++;
             }
-            
-            counter ++;
         }
 
         public void exceptionCaught( IoSession session, Throwable cause )

Modified: directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java (original)
+++ directory/network/trunk/src/test/org/apache/mina/io/IoHandlerFilterChainTest.java Fri
Apr 22 18:54:01 2005
@@ -140,7 +140,7 @@
             return handler;
         }
 
-        public void close()
+        public void close( boolean wait )
         {
         }
 

Modified: directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/protocol/ProtocolHandlerFilterChainTest.java
Fri Apr 22 18:54:01 2005
@@ -146,7 +146,7 @@
             return null;
         }
 
-        public void close() {
+        public void close( boolean wait ) {
         }
 
         public void write(Object message) {

Modified: directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java?rev=164313&r1=164312&r2=164313&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java
Fri Apr 22 18:54:01 2005
@@ -186,7 +186,7 @@
             return null;
         }
 
-        public void close() {
+        public void close( boolean wait ) {
         }
 
         public void write(Object message) {



Mime
View raw message