Return-Path: Delivered-To: apmail-directory-commits-archive@www.apache.org Received: (qmail 73545 invoked from network); 1 Aug 2006 18:14:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Aug 2006 18:14:39 -0000 Received: (qmail 66301 invoked by uid 500); 1 Aug 2006 18:14:39 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 66266 invoked by uid 500); 1 Aug 2006 18:14:39 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 66254 invoked by uid 99); 1 Aug 2006 18:14:38 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Aug 2006 11:14:38 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Aug 2006 11:14:38 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id DD0AE1A981A; Tue, 1 Aug 2006 11:14:17 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r427667 - /directory/trunks/mina/core/src/main/java/org/apache/mina/handler/support/IoSessionOutputStream.java Date: Tue, 01 Aug 2006 18:14:17 -0000 To: commits@directory.apache.org From: niklas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060801181417.DD0AE1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: niklas Date: Tue Aug 1 11:14:17 2006 New Revision: 427667 URL: http://svn.apache.org/viewvc?rev=427667&view=rev Log: Resolved DIRMINA-229 as suggested by Oleg Kalnichevski. The IoSessionOutputStream.write() methods will now block until the bytes have been written. If the write fails or the session has been closed an IOException will be thrown. The close() method will also block now. 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?rev=427667&r1=427666&r2=427667&view=diff ============================================================================== --- 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 Tue Aug 1 11:14:17 2006 @@ -18,10 +18,12 @@ */ package org.apache.mina.handler.support; +import java.io.IOException; import java.io.OutputStream; import org.apache.mina.common.ByteBuffer; import org.apache.mina.common.IoSession; +import org.apache.mina.common.WriteFuture; /** * An {@link OutputStream} that forwards all write operations to @@ -42,41 +44,38 @@ public void close() { - session.close(); + session.close().join(); } - public void flush() + private void checkClosed() throws IOException { - } - - public void write( byte[] b, int off, int len ) - { - if( session.isConnected() ) + if( ! session.isConnected() ) { - ByteBuffer buf = ByteBuffer.wrap( b, off, len ); - buf.acquire(); // prevent from being pooled. - session.write( buf ); + throw new IOException( "The session has been closed." ); } } - - public void write( byte[] b ) + + private void write( ByteBuffer buf ) throws IOException { - if( session.isConnected() ) + checkClosed(); + WriteFuture future = session.write( buf ); + future.join(); + if( ! future.isWritten() ) { - ByteBuffer buf = ByteBuffer.wrap( b ); - buf.acquire(); // prevent from being pooled. - session.write( buf ); + throw new IOException( "The bytes could not be written to the session" ); } } + + public void write( byte[] b, int off, int len ) throws IOException + { + write( ByteBuffer.wrap( b, off, len ) ); + } - public void write( int b ) + public void write( int b ) throws IOException { - if( session.isConnected() ) - { - ByteBuffer buf = ByteBuffer.allocate( 1 ); - buf.put( ( byte ) b ); - buf.flip(); - session.write( buf ); - } + ByteBuffer buf = ByteBuffer.allocate( 1 ); + buf.put( ( byte ) b ); + buf.flip(); + write( buf ); } }