Author: remm Date: Wed Oct 18 17:01:08 2017 New Revision: 1812551 URL: http://svn.apache.org/viewvc?rev=1812551&view=rev Log: Cleanup the async IO syncs a bit.
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java tomcat/trunk/webapps/docs/changelog.xml 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=1812551&r1=1812550&r2=1812551&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Wed Oct 18 17:01:08 2017 @@ -894,14 +894,14 @@ public class Nio2Endpoint extends Abstra } } if (complete) { - readPending.release(); - if (state.block == BlockingMode.BLOCK && currentState != CompletionState.INLINE) { - synchronized (this) { + synchronized (state) { + readPending.release(); + if (state.block == BlockingMode.BLOCK && currentState != CompletionState.INLINE) { + state.state = currentState; + state.notify(); + } else { state.state = currentState; - notify(); } - } else { - state.state = currentState; } if (completion && state.handler != null) { state.handler.completed(Long.valueOf(state.nBytes), state.attachment); @@ -921,14 +921,14 @@ public class Nio2Endpoint extends Abstra ioe = new IOException(exc); } setError(ioe); - readPending.release(); - if (state.block == BlockingMode.BLOCK) { - synchronized (this) { + synchronized (this) { + readPending.release(); + if (state.block == BlockingMode.BLOCK) { + state.state = Nio2Endpoint.isInline() ? CompletionState.ERROR : CompletionState.DONE; + state.notify(); + } else { state.state = Nio2Endpoint.isInline() ? CompletionState.ERROR : CompletionState.DONE; - notify(); } - } else { - state.state = Nio2Endpoint.isInline() ? CompletionState.ERROR : CompletionState.DONE; } if (exc instanceof AsynchronousCloseException) { // If already closed, don't call onError and close again @@ -963,14 +963,14 @@ public class Nio2Endpoint extends Abstra } } if (complete) { - writePending.release(); - if (state.block == BlockingMode.BLOCK && currentState != CompletionState.INLINE) { - synchronized (this) { + synchronized (state) { + writePending.release(); + if (state.block == BlockingMode.BLOCK && currentState != CompletionState.INLINE) { + state.state = currentState; + state.notify(); + } else { state.state = currentState; - notify(); } - } else { - state.state = currentState; } if (completion && state.handler != null) { state.handler.completed(Long.valueOf(state.nBytes), state.attachment); @@ -990,14 +990,14 @@ public class Nio2Endpoint extends Abstra ioe = new IOException(exc); } setError(ioe); - writePending.release(); - if (state.block == BlockingMode.BLOCK) { - synchronized (this) { + synchronized (state) { + writePending.release(); + if (state.block == BlockingMode.BLOCK) { + state.state = Nio2Endpoint.isInline() ? CompletionState.ERROR : CompletionState.DONE; + state.notify(); + } else { state.state = Nio2Endpoint.isInline() ? CompletionState.ERROR : CompletionState.DONE; - notify(); } - } else { - state.state = Nio2Endpoint.isInline() ? CompletionState.ERROR : CompletionState.DONE; } if (state.handler != null) { state.handler.failed(ioe, state.attachment); @@ -1009,6 +1009,11 @@ public class Nio2Endpoint extends Abstra public <A> CompletionState read(ByteBuffer[] dsts, int offset, int length, BlockingMode block, long timeout, TimeUnit unit, A attachment, CompletionCheck check, CompletionHandler<Long, ? super A> handler) { + IOException ioe = getError(); + if (ioe != null) { + handler.failed(ioe, attachment); + return CompletionState.ERROR; + } if (block != BlockingMode.NON_BLOCK) { try { if (!readPending.tryAcquire(timeout, unit)) { @@ -1030,10 +1035,10 @@ public class Nio2Endpoint extends Abstra getSocket().read(dsts, offset, length, timeout, unit, state, completion); Nio2Endpoint.endInline(); if (block == BlockingMode.BLOCK) { - synchronized (completion) { + synchronized (state) { if (state.state == CompletionState.PENDING) { try { - completion.wait(unit.toMillis(timeout)); + state.wait(unit.toMillis(timeout)); if (state.state == CompletionState.PENDING) { handler.failed(new SocketTimeoutException(), attachment); return CompletionState.ERROR; @@ -1085,10 +1090,10 @@ public class Nio2Endpoint extends Abstra getSocket().write(srcs, offset, length, timeout, unit, state, completion); Nio2Endpoint.endInline(); if (block == BlockingMode.BLOCK) { - synchronized (completion) { + synchronized (state) { if (state.state == CompletionState.PENDING) { try { - completion.wait(unit.toMillis(timeout)); + state.wait(unit.toMillis(timeout)); if (state.state == CompletionState.PENDING) { handler.failed(new SocketTimeoutException(), attachment); return CompletionState.ERROR; Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1812551&r1=1812550&r2=1812551&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Wed Oct 18 17:01:08 2017 @@ -74,6 +74,9 @@ have the same password. This fixes PKCS11 key store handling with multiple keys selected with an alias. (markt) </fix> + <fix> + Improve NIO2 syncing for async IO operations. (remm) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org