Skip to content

Commit

Permalink
Simplify Sendfile processing. Rename 'event' so its purpose is clearer.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1655352 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jan 28, 2015
1 parent e431669 commit e10bc0d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions java/org/apache/tomcat/util/net/NioEndpoint.java
Expand Up @@ -1096,7 +1096,8 @@ protected boolean processKey(SelectionKey sk, NioSocketWrapper attachment) {
return result; return result;
} }


public SendfileState processSendfile(SelectionKey sk, NioSocketWrapper socketWrapper, boolean event) { public SendfileState processSendfile(SelectionKey sk, NioSocketWrapper socketWrapper,
boolean calledByProcessor) {
NioChannel sc = null; NioChannel sc = null;
try { try {
unreg(sk, socketWrapper, sk.readyOps()); unreg(sk, socketWrapper, sk.readyOps());
Expand All @@ -1106,13 +1107,7 @@ public SendfileState processSendfile(SelectionKey sk, NioSocketWrapper socketWra
log.trace("Processing send file for: " + sd.fileName); log.trace("Processing send file for: " + sd.fileName);
} }


// This method is called by the Http11Processor for the first if (sd.fchannel == null) {
// execution and then subsequent executions are via the Poller.
// This boolean keeps track of the current caller as the
// required behaviour varies slightly.
boolean calledByProcessor = (sd.fchannel == null);

if (calledByProcessor) {
// Setup the file channel // Setup the file channel
File f = new File(sd.fileName); File f = new File(sd.fileName);
if (!f.exists()) { if (!f.exists()) {
Expand Down Expand Up @@ -1159,16 +1154,15 @@ public SendfileState processSendfile(SelectionKey sk, NioSocketWrapper socketWra
sd.fchannel.close(); sd.fchannel.close();
} catch (Exception ignore) { } catch (Exception ignore) {
} }
// For calls from outside the Poller, the caller is
// responsible for registering the socket for the
// appropriate event(s) if sendfile completes.
if (!calledByProcessor) { if (!calledByProcessor) {
if (sd.keepAlive) { if (sd.keepAlive) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Connection is keep alive, registering back for OP_READ"); log.debug("Connection is keep alive, registering back for OP_READ");
} }
if (event) { reg(sk,socketWrapper,SelectionKey.OP_READ);
this.add(socketWrapper.getSocket(),SelectionKey.OP_READ);
} else {
reg(sk,socketWrapper,SelectionKey.OP_READ);
}
} else { } else {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Send file connection is being closed"); log.debug("Send file connection is being closed");
Expand All @@ -1181,7 +1175,7 @@ public SendfileState processSendfile(SelectionKey sk, NioSocketWrapper socketWra
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("OP_WRITE for sendfile: " + sd.fileName); log.debug("OP_WRITE for sendfile: " + sd.fileName);
} }
if (event) { if (calledByProcessor) {
add(socketWrapper.getSocket(),SelectionKey.OP_WRITE); add(socketWrapper.getSocket(),SelectionKey.OP_WRITE);
} else { } else {
reg(sk,socketWrapper,SelectionKey.OP_WRITE); reg(sk,socketWrapper,SelectionKey.OP_WRITE);
Expand Down

0 comments on commit e10bc0d

Please sign in to comment.