From 9b9f959939f9a6a16e15efbf879390b245adc589 Mon Sep 17 00:00:00 2001 From: fhanik Date: Fri, 21 Jul 2006 19:30:31 +0000 Subject: [PATCH] Make sure the key is valid before processing it 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 | 44 +++++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index b244b7f71..e6773f69e 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -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); -- 2.11.0