Author: markt Date: Wed Jun 1 11:56:03 2016 New Revision: 1746441 URL: http://svn.apache.org/viewvc?rev=1746441&view=rev Log: Pull up synchronization block
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java Modified: tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java?rev=1746441&r1=1746440&r2=1746441&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/AprEndpoint.java Wed Jun 1 11:56:03 2016 @@ -2246,20 +2246,17 @@ public class AprEndpoint extends Abstrac */ protected class SocketProcessor extends SocketProcessorBase<Long> { - public SocketProcessor(SocketWrapperBase<Long> socket, - SocketEvent event) { - super(socket, event); + public SocketProcessor(SocketWrapperBase<Long> socketWrapper, SocketEvent event) { + super(socketWrapper, event); } @Override - public void run() { - synchronized (socketWrapper) { - // Process the request from this socket - SocketState state = getHandler().process(socketWrapper, event); - if (state == Handler.SocketState.CLOSED) { - // Close socket and pool - closeSocket(socketWrapper.getSocket().longValue()); - } + protected void doRun() { + // Process the request from this socket + SocketState state = getHandler().process(socketWrapper, event); + if (state == Handler.SocketState.CLOSED) { + // Close socket and pool + closeSocket(socketWrapper.getSocket().longValue()); } } } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1746441&r1=1746440&r2=1746441&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Wed Jun 1 11:56:03 2016 @@ -1623,95 +1623,93 @@ public class Nio2Endpoint extends Abstra } @Override - public void run() { - synchronized (socketWrapper) { - if (SocketEvent.OPEN_WRITE != event) { - // Anything other than OPEN_WRITE is a genuine read or an - // error condition so for all of those release the semaphore - ((Nio2SocketWrapper) socketWrapper).releaseReadPending(); - } - boolean launch = false; - try { - int handshake = -1; + protected void doRun() { + if (SocketEvent.OPEN_WRITE != event) { + // Anything other than OPEN_WRITE is a genuine read or an + // error condition so for all of those release the semaphore + ((Nio2SocketWrapper) socketWrapper).releaseReadPending(); + } + boolean launch = false; + try { + int handshake = -1; - try { - // For STOP there is no point trying to handshake as the - // Poller has been stopped. - if (!socketWrapper.getSocket().isHandshakeComplete() && event == SocketEvent.ERROR) { - handshake = -1; - } else if (socketWrapper.getSocket().isHandshakeComplete() || - event == SocketEvent.STOP || - event == SocketEvent.ERROR) { - handshake = 0; - } else { - handshake = socketWrapper.getSocket().handshake(); - // The handshake process reads/writes from/to the - // socket. status may therefore be OPEN_WRITE once - // the handshake completes. However, the handshake - // happens when the socket is opened so the status - // must always be OPEN_READ after it completes. It - // is OK to always set this as it is only used if - // the handshake completes. - event = SocketEvent.OPEN_READ; - } - } catch (IOException x) { + try { + // For STOP there is no point trying to handshake as the + // Poller has been stopped. + if (!socketWrapper.getSocket().isHandshakeComplete() && event == SocketEvent.ERROR) { handshake = -1; - if (log.isDebugEnabled()) { - log.debug(sm.getString("endpoint.err.handshake"), x); - } + } else if (socketWrapper.getSocket().isHandshakeComplete() || + event == SocketEvent.STOP || + event == SocketEvent.ERROR) { + handshake = 0; + } else { + handshake = socketWrapper.getSocket().handshake(); + // The handshake process reads/writes from/to the + // socket. status may therefore be OPEN_WRITE once + // the handshake completes. However, the handshake + // happens when the socket is opened so the status + // must always be OPEN_READ after it completes. It + // is OK to always set this as it is only used if + // the handshake completes. + event = SocketEvent.OPEN_READ; } - if (handshake == 0) { - SocketState state = SocketState.OPEN; - // Process the request from this socket - if (event == null) { - state = getHandler().process(socketWrapper, SocketEvent.OPEN_READ); - } else { - state = getHandler().process(socketWrapper, event); - } - if (state == SocketState.CLOSED) { - // Close socket and pool - closeSocket(socketWrapper); - if (running && !paused) { - if (!nioChannels.push(socketWrapper.getSocket())) { - socketWrapper.getSocket().free(); - } - } - } else if (state == SocketState.UPGRADING) { - launch = true; - } - } else if (handshake == -1 ) { + } catch (IOException x) { + handshake = -1; + if (log.isDebugEnabled()) { + log.debug(sm.getString("endpoint.err.handshake"), x); + } + } + if (handshake == 0) { + SocketState state = SocketState.OPEN; + // Process the request from this socket + if (event == null) { + state = getHandler().process(socketWrapper, SocketEvent.OPEN_READ); + } else { + state = getHandler().process(socketWrapper, event); + } + if (state == SocketState.CLOSED) { + // Close socket and pool closeSocket(socketWrapper); if (running && !paused) { if (!nioChannels.push(socketWrapper.getSocket())) { socketWrapper.getSocket().free(); } } + } else if (state == SocketState.UPGRADING) { + launch = true; } - } catch (VirtualMachineError vme) { - ExceptionUtils.handleThrowable(vme); - } catch (Throwable t) { - log.error(sm.getString("endpoint.processing.fail"), t); - if (socketWrapper != null) { - closeSocket(socketWrapper); - } - } finally { - if (launch) { - try { - getExecutor().execute(new SocketProcessor(socketWrapper, SocketEvent.OPEN_READ)); - } catch (NullPointerException npe) { - if (running) { - log.error(sm.getString("endpoint.launch.fail"), - npe); - } + } else if (handshake == -1 ) { + closeSocket(socketWrapper); + if (running && !paused) { + if (!nioChannels.push(socketWrapper.getSocket())) { + socketWrapper.getSocket().free(); } } - socketWrapper = null; - event = null; - //return to cache - if (running && !paused) { - processorCache.push(this); + } + } catch (VirtualMachineError vme) { + ExceptionUtils.handleThrowable(vme); + } catch (Throwable t) { + log.error(sm.getString("endpoint.processing.fail"), t); + if (socketWrapper != null) { + closeSocket(socketWrapper); + } + } finally { + if (launch) { + try { + getExecutor().execute(new SocketProcessor(socketWrapper, SocketEvent.OPEN_READ)); + } catch (NullPointerException npe) { + if (running) { + log.error(sm.getString("endpoint.launch.fail"), + npe); + } } } + socketWrapper = null; + event = null; + //return to cache + if (running && !paused) { + processorCache.push(this); + } } } } Modified: tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?rev=1746441&r1=1746440&r2=1746441&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Wed Jun 1 11:56:03 2016 @@ -1422,82 +1422,76 @@ public class NioEndpoint extends Abstrac */ protected class SocketProcessor extends SocketProcessorBase<NioChannel> { - public SocketProcessor(SocketWrapperBase<NioChannel> ka, SocketEvent event) { - super(ka, event); + public SocketProcessor(SocketWrapperBase<NioChannel> socketWrapper, SocketEvent event) { + super(socketWrapper, event); } @Override - public void run() { + protected void doRun() { NioChannel socket = socketWrapper.getSocket(); - SelectionKey key = socket.getIOChannel().keyFor( - socket.getPoller().getSelector()); + SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); - synchronized (socket) { - try { - int handshake = -1; + try { + int handshake = -1; - try { - if (key != null) { - // For STOP there is no point trying to handshake as the - // Poller has been stopped. - if (socket.isHandshakeComplete() || - event == SocketEvent.STOP) { - handshake = 0; - } else { - handshake = socket.handshake( - key.isReadable(), key.isWritable()); - // The handshake process reads/writes from/to the - // socket. status may therefore be OPEN_WRITE once - // the handshake completes. However, the handshake - // happens when the socket is opened so the status - // must always be OPEN_READ after it completes. It - // is OK to always set this as it is only used if - // the handshake completes. - event = SocketEvent.OPEN_READ; - } - } - } catch (IOException x) { - handshake = -1; - if (log.isDebugEnabled()) log.debug("Error during SSL handshake",x); - } catch (CancelledKeyException ckx) { - handshake = -1; - } - if (handshake == 0) { - SocketState state = SocketState.OPEN; - // Process the request from this socket - if (event == null) { - state = getHandler().process(socketWrapper, SocketEvent.OPEN_READ); + try { + if (key != null) { + // For STOP there is no point trying to handshake as the + // Poller has been stopped. + if (socket.isHandshakeComplete() || event == SocketEvent.STOP) { + handshake = 0; } else { - state = getHandler().process(socketWrapper, event); - } - if (state == SocketState.CLOSED) { - close(socket, key); + handshake = socket.handshake(key.isReadable(), key.isWritable()); + // The handshake process reads/writes from/to the + // socket. status may therefore be OPEN_WRITE once + // the handshake completes. However, the handshake + // happens when the socket is opened so the status + // must always be OPEN_READ after it completes. It + // is OK to always set this as it is only used if + // the handshake completes. + event = SocketEvent.OPEN_READ; } - } else if (handshake == -1 ) { - close(socket, key); - } else if (handshake == SelectionKey.OP_READ){ - socketWrapper.registerReadInterest(); - } else if (handshake == SelectionKey.OP_WRITE){ - socketWrapper.registerWriteInterest(); } - } catch (CancelledKeyException cx) { - socket.getPoller().cancelledKey(key); - } catch (VirtualMachineError vme) { - ExceptionUtils.handleThrowable(vme); - } catch (Throwable t) { - log.error("", t); - socket.getPoller().cancelledKey(key); - } finally { - socketWrapper = null; - event = null; - //return to cache - if (running && !paused) { - processorCache.push(this); + } catch (IOException x) { + handshake = -1; + if (log.isDebugEnabled()) log.debug("Error during SSL handshake",x); + } catch (CancelledKeyException ckx) { + handshake = -1; + } + if (handshake == 0) { + SocketState state = SocketState.OPEN; + // Process the request from this socket + if (event == null) { + state = getHandler().process(socketWrapper, SocketEvent.OPEN_READ); + } else { + state = getHandler().process(socketWrapper, event); + } + if (state == SocketState.CLOSED) { + close(socket, key); } + } else if (handshake == -1 ) { + close(socket, key); + } else if (handshake == SelectionKey.OP_READ){ + socketWrapper.registerReadInterest(); + } else if (handshake == SelectionKey.OP_WRITE){ + socketWrapper.registerWriteInterest(); + } + } catch (CancelledKeyException cx) { + socket.getPoller().cancelledKey(key); + } catch (VirtualMachineError vme) { + ExceptionUtils.handleThrowable(vme); + } catch (Throwable t) { + log.error("", t); + socket.getPoller().cancelledKey(key); + } finally { + socketWrapper = null; + event = null; + //return to cache + if (running && !paused) { + processorCache.push(this); } } } - } // ----------------------------------------------- SendfileData Inner Class Modified: tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java?rev=1746441&r1=1746440&r2=1746441&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/SocketProcessorBase.java Wed Jun 1 11:56:03 2016 @@ -36,4 +36,15 @@ public abstract class SocketProcessorBas this.event = event; } } + + + @Override + public final void run() { + synchronized (socketWrapper) { + doRun(); + } + } + + + protected abstract void doRun(); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org