Author: remm
Date: Mon Sep 14 14:44:06 2015
New Revision: 1702962
URL: http://svn.apache.org/r1702962
Log:
Similar to NIO2, async NIO sendfile needs to deallocate and recycle the buffer.
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java
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=1702962&r1=1702961&r2=1702962&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Mon Sep 14
14:44:06 2015
@@ -552,6 +552,26 @@ public class NioEndpoint extends Abstrac
}
+ 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) {
try {
socket.socket().close();
@@ -984,7 +1004,7 @@ public class NioEndpoint extends Abstrac
if (log.isDebugEnabled()) {
log.debug("Send file connection is being
closed");
}
- cancelledKey(sk);
+ close(sc, sk);
}
}
return SendfileState.DONE;
@@ -1001,11 +1021,19 @@ public class NioEndpoint extends Abstrac
}
} catch (IOException 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;
} catch (Throwable t) {
log.error("", t);
- cancelledKey(sk);
+ if (!calledByProcessor && sc != null) {
+ close(sc, sk);
+ } else {
+ cancelledKey(sk);
+ }
return SendfileState.ERROR;
} finally {
if (sc!=null) sc.setSendFile(false);
@@ -1547,25 +1575,6 @@ public class NioEndpoint extends Abstrac
}
}
- 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
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]