qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject svn commit: r734193 - /qpid/branches/M4-RCs/qpid/java/common/src/main/java/org/apache/qpid/transport/network/ssl/SSLSender.java
Date Tue, 13 Jan 2009 17:32:26 GMT
Author: rajith
Date: Tue Jan 13 09:32:11 2009
New Revision: 734193

URL: http://svn.apache.org/viewvc?rev=734193&view=rev
Log:
This is a fix for QPID-1571
After M4 release we should probably revisit the SSL close logic.
The current fix was done with causing as less impact as possible on the tested code paths.


Modified:
    qpid/branches/M4-RCs/qpid/java/common/src/main/java/org/apache/qpid/transport/network/ssl/SSLSender.java

Modified: qpid/branches/M4-RCs/qpid/java/common/src/main/java/org/apache/qpid/transport/network/ssl/SSLSender.java
URL: http://svn.apache.org/viewvc/qpid/branches/M4-RCs/qpid/java/common/src/main/java/org/apache/qpid/transport/network/ssl/SSLSender.java?rev=734193&r1=734192&r2=734193&view=diff
==============================================================================
--- qpid/branches/M4-RCs/qpid/java/common/src/main/java/org/apache/qpid/transport/network/ssl/SSLSender.java
(original)
+++ qpid/branches/M4-RCs/qpid/java/common/src/main/java/org/apache/qpid/transport/network/ssl/SSLSender.java
Tue Jan 13 09:32:11 2009
@@ -62,8 +62,15 @@
             }
             log.debug("Closing SSL connection");
             engine.closeOutbound();
-            send(ByteBuffer.allocate(0));
-            flush();  
+            try
+            {
+                tearDownSSLConnection();            
+            }
+            catch(Exception e)
+            {
+                throw new RuntimeException("Error closing SSL connection",e);
+            }
+            
             while (!engine.isOutboundDone())
             {
                 synchronized(engineState)
@@ -82,6 +89,37 @@
         }
     }
 
+    private void tearDownSSLConnection() throws Exception
+    {
+        SSLEngineResult result = engine.wrap(ByteBuffer.allocate(0), netData);
+        Status status = result.getStatus();
+        int read   = result.bytesProduced();
+        while (status != Status.CLOSED)
+        {
+            if (status == Status.BUFFER_OVERFLOW)
+            {
+                netData.clear();
+            }
+            if(read > 0)
+            {
+                int limit = netData.limit();
+                netData.limit(netData.position());
+                netData.position(netData.position() - read);
+                
+                ByteBuffer data = netData.slice();
+                
+                netData.limit(limit);
+                netData.position(netData.position() + read);
+                
+                delegate.send(data);
+                flush();
+            }            
+            result = engine.wrap(ByteBuffer.allocate(0), netData);
+            status = result.getStatus();             
+            read   = result.bytesProduced();
+        }
+    }
+    
     public void flush()
     {
         delegate.flush();        
@@ -92,7 +130,7 @@
         if (closed.get())
         {
             throw new SenderException("SSL Sender is closed");
-        }   
+        }
 
         HandshakeStatus handshakeStatus;
         Status status;



Mime
View raw message