directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r122701 - /incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
Date Sat, 18 Dec 2004 04:01:09 GMT
Author: trustin
Date: Fri Dec 17 20:01:07 2004
New Revision: 122701

URL: http://svn.apache.org/viewcvs?view=rev&rev=122701
Log:
Fixed: Inifiite loop if user flushes empty write buffer.
Modified:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java?view=diff&rev=122701&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r1=122700&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r2=122701
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
Fri Dec 17 20:01:07 2004
@@ -327,22 +327,14 @@
     private void notifyIdleSession( TcpSession session, long currentTime )
     {
         SessionConfig config = session.getConfig();
-        notifyIdleSession0(
-                            session,
-                            currentTime,
-                            config.getIdleTimeInMillis( IdleStatus.BOTH_IDLE ),
+        notifyIdleSession0( session, currentTime, config
+                .getIdleTimeInMillis( IdleStatus.BOTH_IDLE ),
                             IdleStatus.BOTH_IDLE, session.getLastIoTime() );
-        notifyIdleSession0(
-                            session,
-                            currentTime,
-                            config
-                                  .getIdleTimeInMillis( IdleStatus.READER_IDLE ),
+        notifyIdleSession0( session, currentTime, config
+                .getIdleTimeInMillis( IdleStatus.READER_IDLE ),
                             IdleStatus.READER_IDLE, session.getLastReadTime() );
-        notifyIdleSession0(
-                            session,
-                            currentTime,
-                            config
-                                  .getIdleTimeInMillis( IdleStatus.WRITER_IDLE ),
+        notifyIdleSession0( session, currentTime, config
+                .getIdleTimeInMillis( IdleStatus.WRITER_IDLE ),
                             IdleStatus.WRITER_IDLE, session.getLastWriteTime() );
     }
 
@@ -393,63 +385,82 @@
             synchronized( lock )
             {
                 writeBuf.flip();
-
-                int writtenBytes;
-
-                try
-                {
-                    writtenBytes = ch.write( writeBuf );
-                }
-                finally
+                
+                // ignore empty write buffer
+                if( writeBuf.remaining() == 0 )
                 {
-                    SelectionKey key = session.getSelectionKey();
-
-                    if( writeBuf.hasRemaining() )
-                    {
-                        // Kernel buffer is full
-                        key.interestOps( key.interestOps()
-                                         | SelectionKey.OP_WRITE );
-                    }
-                    else
-                    {
-                        key.interestOps( key.interestOps()
-                                         & ( ~SelectionKey.OP_WRITE ) );
-                    }
-
-                    writeBuf.compact();
-                    writeBuf.mark();
-                }
+                    writeBuf.clear();
 
-                if( writtenBytes > 0 )
-                {
-                    session.increaseWrittenBytes( writtenBytes );
-                    lock.markBaseIndex();
-                    fireDataWritten( session, writtenBytes );
                     Queue markers = lock.getMarkers();
                     for( ;; )
                     {
                         TcpWriteBuffer.Marker marker = ( TcpWriteBuffer.Marker ) markers
-                                                                                        .first();
+                                .pop();
                         if( marker == null )
                             break;
 
-                        int bytesLeft = marker.getBytesLeft();
-                        if( bytesLeft > writtenBytes )
+                        fireMarkerRemoved( session, marker.getValue() );
+                    }
+                }
+                else
+                {
+                    int writtenBytes;
+
+                    try
+                    {
+                        writtenBytes = ch.write( writeBuf );
+                    }
+                    finally
+                    {
+                        SelectionKey key = session.getSelectionKey();
+
+                        if( writeBuf.hasRemaining() )
                         {
-                            marker.setBytesLeft( bytesLeft - writtenBytes );
-                            break;
+                            // Kernel buffer is full
+                            key.interestOps( key.interestOps()
+                                             | SelectionKey.OP_WRITE );
                         }
-                        else if( bytesLeft == writtenBytes )
+                        else
                         {
-                            markers.pop();
-                            fireMarkerRemoved( session, marker.getValue() );
-                            break;
+                            key.interestOps( key.interestOps()
+                                             & ( ~SelectionKey.OP_WRITE ) );
                         }
-                        else
+
+                        writeBuf.compact();
+                        writeBuf.mark();
+                    }
+
+                    if( writtenBytes > 0 )
+                    {
+                        session.increaseWrittenBytes( writtenBytes );
+                        lock.markBaseIndex();
+                        fireDataWritten( session, writtenBytes );
+                        Queue markers = lock.getMarkers();
+                        for( ;; )
                         {
-                            markers.pop();
-                            fireMarkerRemoved( session, marker.getValue() );
-                            writtenBytes -= bytesLeft;
+                            TcpWriteBuffer.Marker marker = ( TcpWriteBuffer.Marker ) markers
+                                    .first();
+                            if( marker == null )
+                                break;
+
+                            int bytesLeft = marker.getBytesLeft();
+                            if( bytesLeft > writtenBytes )
+                            {
+                                marker.setBytesLeft( bytesLeft - writtenBytes );
+                                break;
+                            }
+                            else if( bytesLeft == writtenBytes )
+                            {
+                                markers.pop();
+                                fireMarkerRemoved( session, marker.getValue() );
+                                break;
+                            }
+                            else
+                            {
+                                markers.pop();
+                                fireMarkerRemoved( session, marker.getValue() );
+                                writtenBytes -= bytesLeft;
+                            }
                         }
                     }
                 }

Mime
View raw message