From cbc269c7765077aec1732a92675e0cbc433a88ef Mon Sep 17 00:00:00 2001 From: fhanik Date: Sat, 14 Apr 2007 16:47:20 +0000 Subject: [PATCH] remove duplicate code, cause of all my headaches git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@528837 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/tomcat/util/net/NioEndpoint.java | 58 ++++-------------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 2e76cad05..835924513 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1855,53 +1855,11 @@ public class NioEndpoint { } } else { - socket = (NioChannel)channel; - key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); - int handshake = -1; - - try { - if (key!=null) handshake = socket.handshake(key.isReadable(), key.isWritable()); - }catch ( IOException x ) { - handshake = -1; - if ( log.isDebugEnabled() ) log.debug("Error during SSL handshake",x); - }catch ( CancelledKeyException ckx ) { - handshake = -1; - } - if ( handshake == 0 ) { - // Process the request from this socket - boolean closed = (status==null)?(handler.process(socket)==Handler.SocketState.CLOSED) : - (handler.event(socket,status)==Handler.SocketState.CLOSED); - - if (closed) { - // Close socket and pool - try { - KeyAttachment ka = null; - if (key!=null) { - ka = (KeyAttachment) key.attachment(); - if (ka!=null) ka.setComet(false); - socket.getPoller().cancelledKey(key, SocketStatus.ERROR, false); - } - nioChannels.offer(socket); - if ( ka!=null ) keyCache.offer(ka); - }catch ( Exception x ) { - log.error("",x); - } - } - } else if (handshake == -1 ) { - KeyAttachment ka = null; - if (key!=null) { - ka = (KeyAttachment) key.attachment(); - socket.getPoller().cancelledKey(key, SocketStatus.DISCONNECT, false); - } - nioChannels.offer(socket); - if ( ka!=null ) keyCache.offer(ka); - } else { - final SelectionKey fk = key; - final int intops = handshake; - final KeyAttachment ka = (KeyAttachment)fk.attachment(); - ka.getPoller().add(socket,intops); - } + SocketProcessor sc = processorCache.poll(); + if ( sc == null ) sc = new SocketProcessor(socket,status); + else sc.reset(socket,status); + sc.run(); } }catch(CancelledKeyException cx) { if (socket!=null && key!=null) socket.getPoller().cancelledKey(key,null,false); @@ -2084,8 +2042,10 @@ public class NioEndpoint { if (ka!=null) ka.setComet(false); socket.getPoller().cancelledKey(key, SocketStatus.ERROR, false); } - nioChannels.offer(socket); + if (socket!=null) nioChannels.offer(socket); + socket = null; if ( ka!=null ) keyCache.offer(ka); + ka = null; }catch ( Exception x ) { log.error("",x); } @@ -2096,8 +2056,10 @@ public class NioEndpoint { ka = (KeyAttachment) key.attachment(); socket.getPoller().cancelledKey(key, SocketStatus.DISCONNECT, false); } - nioChannels.offer(socket); + if (socket!=null) nioChannels.offer(socket); + socket = null; if ( ka!=null ) keyCache.offer(ka); + ka = null; } else { final SelectionKey fk = key; final int intops = handshake; -- 2.11.0