directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r446482 - /directory/trunks/mina/core/src/main/java/org/apache/mina/handler/support/IoSessionOutputStream.java
Date Fri, 15 Sep 2006 02:52:58 GMT
Author: trustin
Date: Thu Sep 14 19:52:57 2006
New Revision: 446482

URL: http://svn.apache.org/viewvc?view=rev&rev=446482
Log:
Changed IoSessionOutputStream to wait for the WriteFuture only when a user calls flush().

Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/handler/support/IoSessionOutputStream.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/handler/support/IoSessionOutputStream.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/core/src/main/java/org/apache/mina/handler/support/IoSessionOutputStream.java?view=diff&rev=446482&r1=446481&r2=446482
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/handler/support/IoSessionOutputStream.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/handler/support/IoSessionOutputStream.java
Thu Sep 14 19:52:57 2006
@@ -37,12 +37,13 @@
 public class IoSessionOutputStream extends OutputStream
 {
     private final IoSession session;
+    private WriteFuture lastWriteFuture;
     
     public IoSessionOutputStream( IoSession session )
     {
         this.session = session;
     }
-
+    
     public void close()
     {
         session.close().join();
@@ -56,15 +57,11 @@
         }
     }
     
-    private void write( ByteBuffer buf ) throws IOException
+    private synchronized void write( ByteBuffer buf ) throws IOException
     {
         checkClosed();
         WriteFuture future = session.write( buf );
-        future.join();
-        if( ! future.isWritten() )
-        {
-            throw new IOException( "The bytes could not be written to the session" );
-        }
+        lastWriteFuture = future;
     }
     
     public void write( byte[] b, int off, int len ) throws IOException
@@ -78,5 +75,19 @@
         buf.put( ( byte ) b );
         buf.flip();
         write( buf );
+    }
+    
+    public synchronized void flush() throws IOException
+    {
+        if( lastWriteFuture == null )
+        {
+            return;
+        }
+        
+        lastWriteFuture.join();
+        if( !lastWriteFuture.isWritten() )
+        {
+            throw new IOException( "The bytes could not be written to the session" );
+        }
     }
 }



Mime
View raw message