directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r330742 - in /directory/network: branches/0.8/src/java/org/apache/mina/io/datagram/ branches/0.8/src/java/org/apache/mina/io/socket/ trunk/src/java/org/apache/mina/transport/socket/nio/support/
Date Fri, 04 Nov 2005 07:43:22 GMT
Author: trustin
Date: Thu Nov  3 23:43:12 2005
New Revision: 330742

URL: http://svn.apache.org/viewcvs?rev=330742&view=rev
Log:
Related issue: DIRMINA-115 Unexpected CancelledKeyException
* Added more SelectionKey check code


Modified:
    directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
    directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramConnector.java
    directory/network/branches/0.8/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java

Modified: directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java?rev=330742&r1=330741&r2=330742&view=diff
==============================================================================
--- directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
(original)
+++ directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramAcceptor.java
Thu Nov  3 23:43:12 2005
@@ -441,10 +441,20 @@
                 continue;
             }
 
+            SelectionKey key = session.getSelectionKey();
+            if( key == null )
+            {
+                scheduleFlush( session );
+                break;
+            }
+            if( !key.isValid() )
+            {
+                continue;
+            }
+
             int writtenBytes = ch
                     .send( buf.buf(), session.getRemoteAddress() );
 
-            SelectionKey key = session.getSelectionKey();
             if( writtenBytes == 0 )
             {
                 // Kernel buffer is full

Modified: directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramConnector.java?rev=330742&r1=330741&r2=330742&view=diff
==============================================================================
--- directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramConnector.java
(original)
+++ directory/network/branches/0.8/src/java/org/apache/mina/io/datagram/DatagramConnector.java
Thu Nov  3 23:43:12 2005
@@ -396,9 +396,19 @@
                 continue;
             }
 
+            SelectionKey key = session.getSelectionKey();
+            if( key == null )
+            {
+                scheduleFlush( session );
+                break;
+            }
+            if( !key.isValid() )
+            {
+                continue;
+            }
+
             int writtenBytes = ch.write( buf.buf() );
 
-            SelectionKey key = session.getSelectionKey();
             if( writtenBytes == 0 )
             {
                 // Kernel buffer is full

Modified: directory/network/branches/0.8/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.8/src/java/org/apache/mina/io/socket/SocketIoProcessor.java?rev=330742&r1=330741&r2=330742&view=diff
==============================================================================
--- directory/network/branches/0.8/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
(original)
+++ directory/network/branches/0.8/src/java/org/apache/mina/io/socket/SocketIoProcessor.java
Thu Nov  3 23:43:12 2005
@@ -19,7 +19,6 @@
 package org.apache.mina.io.socket;
 
 import java.io.IOException;
-import java.nio.channels.CancelledKeyException;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;
@@ -379,10 +378,11 @@
                                            long currentTime,
                                            long writeTimeout, long lastIoTime )
     {
+        SelectionKey key = session.getSelectionKey();
         if( writeTimeout > 0
             && ( currentTime - lastIoTime ) >= writeTimeout
-            && session.getSelectionKey() != null
-            && ( session.getSelectionKey().interestOps() & SelectionKey.OP_WRITE
) != 0 )
+            && key != null && key.isValid()
+            && ( key.interestOps() & SelectionKey.OP_WRITE ) != 0 )
         {
             session
                     .getManagerFilterChain()
@@ -415,28 +415,26 @@
 
             // If encountered write request before session is initialized, 
             // (In case that Session.write() is called before addSession() is processed)
-            if( session.getSelectionKey() == null )
+            SelectionKey key = session.getSelectionKey();
+            if( key == null )
             {
                 // Reschedule for later write
                 scheduleFlush( session );
                 break;
             }
-            else
+            if( !key.isValid() )
             {
-                try
-                {
-                    flush( session );
-                }
-                catch( CancelledKeyException e )
-                {
-                    // Connection is closed unexpectedly.
-                    scheduleRemove( session );
-                }
-                catch( IOException e )
-                {
-                    scheduleRemove( session );
-                    session.getManagerFilterChain().exceptionCaught( session, e );
-                }
+                continue;
+            }
+            
+            try
+            {
+                flush( session );
+            }
+            catch( IOException e )
+            {
+                scheduleRemove( session );
+                session.getManagerFilterChain().exceptionCaught( session, e );
             }
         }
     }

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java?rev=330742&r1=330741&r2=330742&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramAcceptorDelegate.java
Thu Nov  3 23:43:12 2005
@@ -433,11 +433,21 @@
                 continue;
             }
 
+            SelectionKey key = session.getSelectionKey();
+            if( key == null )
+            {
+                scheduleFlush( session );
+                break;
+            }
+            if( !key.isValid() )
+            {
+                continue;
+            }
+
             int pos = buf.position();
             int writtenBytes = ch
                     .send( buf.buf(), session.getRemoteAddress() );
 
-            SelectionKey key = session.getSelectionKey();
             if( writtenBytes == 0 )
             {
                 // Kernel buffer is full

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java?rev=330742&r1=330741&r2=330742&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/DatagramConnectorDelegate.java
Thu Nov  3 23:43:12 2005
@@ -356,10 +356,20 @@
                 continue;
             }
 
+            SelectionKey key = session.getSelectionKey();
+            if( key == null )
+            {
+                scheduleFlush( session );
+                break;
+            }
+            if( !key.isValid() )
+            {
+                continue;
+            }
+
             int pos = buf.position();
             int writtenBytes = ch.write( buf.buf() );
 
-            SelectionKey key = session.getSelectionKey();
             if( writtenBytes == 0 )
             {
                 // Kernel buffer is full

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java?rev=330742&r1=330741&r2=330742&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/support/SocketIoProcessor.java
Thu Nov  3 23:43:12 2005
@@ -19,7 +19,6 @@
 package org.apache.mina.transport.socket.nio.support;
 
 import java.io.IOException;
-import java.nio.channels.CancelledKeyException;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
 import java.nio.channels.SocketChannel;
@@ -219,7 +218,6 @@
                 scheduleRemove( session );
                 break;
             }
-
             // skip if channel is already closed
             if( !key.isValid() )
             {
@@ -376,10 +374,11 @@
                                            long currentTime,
                                            long writeTimeout, long lastIoTime )
     {
+        SelectionKey key = session.getSelectionKey();
         if( writeTimeout > 0
             && ( currentTime - lastIoTime ) >= writeTimeout
-            && session.getSelectionKey() != null
-            && ( session.getSelectionKey().interestOps() & SelectionKey.OP_WRITE
) != 0 )
+            && key != null && key.isValid()
+            && ( key.interestOps() & SelectionKey.OP_WRITE ) != 0 )
         {
             session
                     .getManagerFilterChain()
@@ -410,30 +409,28 @@
                 continue;
             }
             
-            // If encountered write request before session is initialized, 
+            SelectionKey key = session.getSelectionKey();
+            // Retry later if session is not yet fully initialized.
             // (In case that Session.write() is called before addSession() is processed)
-            if( session.getSelectionKey() == null )
+            if( key == null )
             {
-                // Reschedule for later write
                 scheduleFlush( session );
                 break;
             }
-            else
+            // skip if channel is already closed
+            if( !key.isValid() )
             {
-                try
-                {
-                    doFlush( session );
-                }
-                catch( CancelledKeyException e )
-                {
-                    // Connection is closed unexpectedly.
-                    scheduleRemove( session );
-                }
-                catch( IOException e )
-                {
-                    scheduleRemove( session );
-                    session.getManagerFilterChain().exceptionCaught( session, e );
-                }
+                continue;
+            }
+
+            try
+            {
+                doFlush( session );
+            }
+            catch( IOException e )
+            {
+                scheduleRemove( session );
+                session.getManagerFilterChain().exceptionCaught( session, e );
             }
         }
     }
@@ -535,6 +532,11 @@
                 scheduleTrafficControl( session );
                 break;
             }
+            // skip if channel is already closed
+            if( !key.isValid() )
+            {
+                continue;
+            }
 
             // The normal is OP_READ and, if there are write requests in the
             // session's write queue, set OP_WRITE to trigger flushing.
@@ -550,16 +552,7 @@
 
             // Now mask the preferred ops with the mask of the current session
             int mask = session.getTrafficMask().getInterestOps();
-
-            try
-            {
-                key.interestOps( ops & mask );
-            }
-            catch( CancelledKeyException e )
-            {
-                // Connection is closed unexpectedly.
-                scheduleRemove( session );
-            }
+            key.interestOps( ops & mask );
         }
     }
     



Mime
View raw message