This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new b03fcaf Revert change to use a latch b03fcaf is described below commit b03fcaf67a91b08e533c5bc0c460075201e6b22a Author: remm <r...@apache.org> AuthorDate: Mon Mar 9 21:22:32 2020 +0100 Revert change to use a latch --- java/org/apache/tomcat/util/net/NioEndpoint.java | 102 ++++++++++++++--------- webapps/docs/changelog.xml | 7 -- 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 2019680..bbcf4ca 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -722,8 +722,11 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> if (!socketWrapper.readOperation.process()) { closeSocket = true; } - } else if (socketWrapper.readBlock != null) { - socketWrapper.readBlock.countDown(); + } else if (socketWrapper.readBlocking) { + synchronized (socketWrapper.readLock) { + socketWrapper.readBlocking = false; + socketWrapper.readLock.notify(); + } } else if (!processSocket(socketWrapper, SocketEvent.OPEN_READ, true)) { closeSocket = true; } @@ -733,8 +736,11 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> if (!socketWrapper.writeOperation.process()) { closeSocket = true; } - } else if (socketWrapper.writeBlock != null) { - socketWrapper.writeBlock.countDown(); + } else if (socketWrapper.writeBlocking) { + synchronized (socketWrapper.writeLock) { + socketWrapper.writeBlocking = false; + socketWrapper.writeLock.notify(); + } } else if (!processSocket(socketWrapper, SocketEvent.OPEN_WRITE, true)) { closeSocket = true; } @@ -975,14 +981,18 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> private volatile long lastRead = System.currentTimeMillis(); private volatile long lastWrite = lastRead; - private CountDownLatch readBlock; - private CountDownLatch writeBlock; + private final Object readLock; + private volatile boolean readBlocking = false; + private final Object writeLock; + private volatile boolean writeBlocking = false; public NioSocketWrapper(NioChannel channel, NioEndpoint endpoint) { super(channel, endpoint); nioChannels = endpoint.getNioChannels(); poller = endpoint.getPoller(); socketBufferHandler = channel.getBufHandler(); + readLock = (readPending == null) ? new Object() : readPending; + writeLock = (writePending == null) ? new Object() : writePending; } public Poller getPoller() { return poller; } @@ -1139,23 +1149,30 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> if (block && nRead == 0) { long timeout = getReadTimeout(); try { - readBlock = new CountDownLatch(1); + readBlocking = true; registerReadInterest(); - if (timeout > 0) { - if (!readBlock.await(timeout, TimeUnit.MILLISECONDS)) { - throw new SocketTimeoutException(); + synchronized (readLock) { + if (readBlocking) { + try { + if (timeout > 0) { + readLock.wait(timeout); + } else { + readLock.wait(); + } + } catch (InterruptedException e) { + // Continue ... + } + if (readBlocking) { + throw new SocketTimeoutException(); + } } - } else { - readBlock.await(); } - } catch (InterruptedException e) { - throw new EOFException(); + nRead = socket.read(to); + if (nRead == -1) { + throw new EOFException(); + } } finally { - readBlock = null; - } - nRead = socket.read(to); - if (nRead == -1) { - throw new EOFException(); + readBlocking = false; } } return nRead; @@ -1170,30 +1187,37 @@ public class NioEndpoint extends AbstractJsseEndpoint<NioChannel,SocketChannel> } if (block) { long timeout = getWriteTimeout(); - int n = 0; - do { - n = socket.write(from); - if (n == -1) { - throw new EOFException(); - } - if (n == 0) { - try { - writeBlock = new CountDownLatch(1); + try { + int n = 0; + do { + n = socket.write(from); + if (n == -1) { + throw new EOFException(); + } + if (n == 0) { + writeBlocking = true; registerWriteInterest(); - if (timeout > 0) { - if (!writeBlock.await(timeout, TimeUnit.MILLISECONDS)) { - throw new SocketTimeoutException(); + synchronized (writeLock) { + if (writeBlocking) { + try { + if (timeout > 0) { + writeLock.wait(timeout); + } else { + writeLock.wait(); + } + } catch (InterruptedException e) { + // Continue ... + } + if (writeBlocking) { + throw new SocketTimeoutException(); + } } - } else { - writeBlock.await(); } - } catch (InterruptedException e) { - throw new EOFException(); - } finally { - writeBlock = null; } - } - } while (from.hasRemaining()); + } while (from.hasRemaining()); + } finally { + writeBlocking = false; + } // If there is data left in the buffer the socket will be registered for // write further up the stack. This is to ensure the socket is only // registered for write once as both container and user code can trigger diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 55c2e24..eb453ac 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -45,13 +45,6 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 10.0.0-M3 (markt)" rtext="in development"> - <subsection name="Coyote"> - <changelog> - <fix> - Use a latch again for NIO blocking reads and writes. (remm) - </fix> - </changelog> - </subsection> <subsection name="Other"> <changelog> <fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org