Skip to content

Commit

Permalink
Code cleanup and remove the extra readInterest = true, they don't see…
Browse files Browse the repository at this point in the history
…m to be useful.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1853973 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmaucher committed Feb 20, 2019
1 parent fde6ec2 commit 6d3ee3a
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions java/org/apache/tomcat/util/net/Nio2Endpoint.java
Expand Up @@ -473,7 +473,7 @@ protected AtomicInteger initialValue() {


private SendfileData sendfileData = null; private SendfileData sendfileData = null;


private final CompletionHandler<Integer, SocketWrapperBase<Nio2Channel>> readCompletionHandler; private final CompletionHandler<Integer, ByteBuffer> readCompletionHandler;
private final Semaphore readPending = new Semaphore(1); private final Semaphore readPending = new Semaphore(1);
private boolean readInterest = false; // Guarded by readCompletionHandler private boolean readInterest = false; // Guarded by readCompletionHandler


Expand Down Expand Up @@ -587,12 +587,12 @@ public Nio2SocketWrapper(Nio2Channel channel, final Nio2Endpoint endpoint) {
super(channel, endpoint); super(channel, endpoint);
socketBufferHandler = channel.getBufHandler(); socketBufferHandler = channel.getBufHandler();


this.readCompletionHandler = new CompletionHandler<Integer, SocketWrapperBase<Nio2Channel>>() { this.readCompletionHandler = new CompletionHandler<Integer, ByteBuffer>() {
@Override @Override
public void completed(Integer nBytes, SocketWrapperBase<Nio2Channel> attachment) { public void completed(Integer nBytes, ByteBuffer attachment) {
boolean notify = false; boolean notify = false;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Socket: [" + attachment + "], Interest: [" + readInterest + "]"); log.debug("Socket: [" + Nio2SocketWrapper.this + "], Interest: [" + readInterest + "]");
} }
synchronized (readCompletionHandler) { synchronized (readCompletionHandler) {
if (nBytes.intValue() < 0) { if (nBytes.intValue() < 0) {
Expand All @@ -609,11 +609,11 @@ public void completed(Integer nBytes, SocketWrapperBase<Nio2Channel> attachment)
} }
} }
if (notify) { if (notify) {
getEndpoint().processSocket(attachment, SocketEvent.OPEN_READ, false); getEndpoint().processSocket(Nio2SocketWrapper.this, SocketEvent.OPEN_READ, false);
} }
} }
@Override @Override
public void failed(Throwable exc, SocketWrapperBase<Nio2Channel> attachment) { public void failed(Throwable exc, ByteBuffer attachment) {
IOException ioe; IOException ioe;
if (exc instanceof IOException) { if (exc instanceof IOException) {
ioe = (IOException) exc; ioe = (IOException) exc;
Expand All @@ -628,7 +628,7 @@ public void failed(Throwable exc, SocketWrapperBase<Nio2Channel> attachment) {
// If already closed, don't call onError and close again // If already closed, don't call onError and close again
return; return;
} }
getEndpoint().processSocket(attachment, SocketEvent.ERROR, true); getEndpoint().processSocket(Nio2SocketWrapper.this, SocketEvent.ERROR, true);
} }
}; };


Expand Down Expand Up @@ -810,8 +810,6 @@ public int read(boolean block, byte[] b, int off, int len) throws IOException {
socketBufferHandler.configureReadBufferForRead(); socketBufferHandler.configureReadBufferForRead();
nRead = Math.min(nRead, len); nRead = Math.min(nRead, len);
socketBufferHandler.getReadBuffer().get(b, off, nRead); socketBufferHandler.getReadBuffer().get(b, off, nRead);
} else if (nRead == 0 && !block && ContainerThreadMarker.isContainerThread()) {
readInterest = true;
} }
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Socket: [" + this + "], Read: [" + nRead + "]"); log.debug("Socket: [" + this + "], Read: [" + nRead + "]");
Expand Down Expand Up @@ -873,8 +871,6 @@ public int read(boolean block, ByteBuffer to) throws IOException {
// data that was just read // data that was just read
if (nRead > 0) { if (nRead > 0) {
nRead = populateReadBuffer(to); nRead = populateReadBuffer(to);
} else if (nRead == 0 && !block && ContainerThreadMarker.isContainerThread()) {
readInterest = true;
} }
} }


Expand Down Expand Up @@ -1226,7 +1222,7 @@ private int fillReadBuffer(boolean block, ByteBuffer to) throws IOException {
} }
} else { } else {
Nio2Endpoint.startInline(); Nio2Endpoint.startInline();
getSocket().read(to, toNio2Timeout(getReadTimeout()), TimeUnit.MILLISECONDS, this, getSocket().read(to, toNio2Timeout(getReadTimeout()), TimeUnit.MILLISECONDS, to,
readCompletionHandler); readCompletionHandler);
Nio2Endpoint.endInline(); Nio2Endpoint.endInline();
if (readPending.availablePermits() == 1) { if (readPending.availablePermits() == 1) {
Expand Down

0 comments on commit 6d3ee3a

Please sign in to comment.