Skip to content

Commit

Permalink
Similar to NIO2, async NIO sendfile needs to deallocate and recycle t…
Browse files Browse the repository at this point in the history
…he buffer.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1702962 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
rmaucher committed Sep 14, 2015
1 parent 30e39e3 commit 41e922c
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions java/org/apache/tomcat/util/net/NioEndpoint.java
Expand Up @@ -552,6 +552,26 @@ public void run() {
} }




private void close(NioChannel socket, SelectionKey key) {
try {
if (socket.getPoller().cancelledKey(key) != null) {
// SocketWrapper (attachment) was removed from the
// key - recycle the key. This can only happen once
// per attempted closure so it is used to determine
// whether or not to return the key to the cache.
// We do NOT want to do this more than once - see BZ
// 57340 / 57943.
if (running && !paused) {
if (!nioChannels.push(socket)) {
socket.free();
}
}
}
} catch (Exception x) {
log.error("",x);
}
}

private void closeSocket(SocketChannel socket) { private void closeSocket(SocketChannel socket) {
try { try {
socket.socket().close(); socket.socket().close();
Expand Down Expand Up @@ -984,7 +1004,7 @@ public SendfileState processSendfile(SelectionKey sk, NioSocketWrapper socketWra
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Send file connection is being closed"); log.debug("Send file connection is being closed");
} }
cancelledKey(sk); close(sc, sk);
} }
} }
return SendfileState.DONE; return SendfileState.DONE;
Expand All @@ -1001,11 +1021,19 @@ public SendfileState processSendfile(SelectionKey sk, NioSocketWrapper socketWra
} }
} catch (IOException x) { } catch (IOException x) {
if (log.isDebugEnabled()) log.debug("Unable to complete sendfile request:", x); if (log.isDebugEnabled()) log.debug("Unable to complete sendfile request:", x);
cancelledKey(sk); if (!calledByProcessor && sc != null) {
close(sc, sk);
} else {
cancelledKey(sk);
}
return SendfileState.ERROR; return SendfileState.ERROR;
} catch (Throwable t) { } catch (Throwable t) {
log.error("", t); log.error("", t);
cancelledKey(sk); if (!calledByProcessor && sc != null) {
close(sc, sk);
} else {
cancelledKey(sk);
}
return SendfileState.ERROR; return SendfileState.ERROR;
} finally { } finally {
if (sc!=null) sc.setSendFile(false); if (sc!=null) sc.setSendFile(false);
Expand Down Expand Up @@ -1547,25 +1575,6 @@ public void run() {
} }
} }


private void close(NioChannel socket, SelectionKey key) {
try {
if (socket.getPoller().cancelledKey(key) != null) {
// SocketWrapper (attachment) was removed from the
// key - recycle the key. This can only happen once
// per attempted closure so it is used to determine
// whether or not to return the key to the cache.
// We do NOT want to do this more than once - see BZ
// 57340 / 57943.
if (running && !paused) {
if (!nioChannels.push(socket)) {
socket.free();
}
}
}
} catch (Exception x) {
log.error("",x);
}
}
} }


// ----------------------------------------------- SendfileData Inner Class // ----------------------------------------------- SendfileData Inner Class
Expand Down

0 comments on commit 41e922c

Please sign in to comment.