Make sure the key is valid before processing it
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 21 Jul 2006 19:30:31 +0000 (19:30 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 21 Jul 2006 19:30:31 +0000 (19:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@424429 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/net/NioEndpoint.java

index b244b7f..e6773f6 100644 (file)
@@ -1133,29 +1133,31 @@ public class NioEndpoint {
                     iterator.remove();
                     KeyAttachment attachment = (KeyAttachment)sk.attachment();
                     try {
-                        if(attachment == null) attachment = new KeyAttachment();
-                        attachment.access();
-                        sk.attach(attachment);
-
-                        int readyOps = sk.readyOps();
-                        sk.interestOps(sk.interestOps() & ~readyOps);
-                        SocketChannel channel = (SocketChannel)sk.channel();
-                        boolean read = sk.isReadable();
-                        if (read) {
-                            if ( attachment.getWakeUp() ) {
-                                attachment.setWakeUp(false);
-                                synchronized (attachment.getMutex()) {attachment.getMutex().notifyAll();}
-                            } else if ( attachment.getComet() ) {
-                                if (!processSocket(channel,false)) processSocket(channel,true);
-                            } else {
-                                boolean close = (!processSocket(channel));
-                                if ( close ) {
-                                    channel.socket().close();
-                                    channel.close();
+                        if ( sk.isValid() ) {
+                            if(attachment == null) attachment = new KeyAttachment();
+                            attachment.access();
+                            sk.attach(attachment);
+                            int readyOps = sk.readyOps();
+                            sk.interestOps(sk.interestOps() & ~readyOps);
+                            SocketChannel channel = (SocketChannel)sk.channel();
+                            boolean read = sk.isReadable();
+                            if (read) {
+                                if ( attachment.getWakeUp() ) {
+                                    attachment.setWakeUp(false);
+                                    synchronized (attachment.getMutex()) {attachment.getMutex().notifyAll();}
+                                } else if ( attachment.getComet() ) {
+                                    if (!processSocket(channel,false)) processSocket(channel,true);
+                                } else {
+                                    boolean close = (!processSocket(channel));
+                                    if ( close ) {
+                                        channel.socket().close();
+                                        channel.close();
+                                    }
                                 }
                             }
-                        }
-                        if (sk.isValid() && sk.isWritable()) {
+                        } else {
+                            //invalid key
+                            cancelledKey(sk);
                         }
                     } catch ( CancelledKeyException ckx ) {
                         if (attachment!=null && attachment.getComet()) processSocket( (SocketChannel) sk.channel(), true);