You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2005/04/20 18:13:23 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets DefaultServlet.java
remm 2005/04/20 09:13:23
Modified: catalina/src/share/org/apache/naming/resources
ResourceAttributes.java FileDirContext.java
http11/src/java/org/apache/coyote/http11
InternalAprOutputBuffer.java
Http11AprProcessor.java
util/java/org/apache/tomcat/util/net AprEndpoint.java
catalina/src/share/org/apache/catalina/connector
Request.java
catalina/src/share/org/apache/catalina/servlets
DefaultServlet.java
Log:
- Fix setting timeouts on sockets.
- Add plumbing code for sendfile (disabled by default), which doesn't work yet.
- Apparently, the Sendfile.run algo is bad. APR is black magic to me, so I'll let Mladen fix it :)
Revision Changes Path
1.6 +13 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ResourceAttributes.java
Index: ResourceAttributes.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ResourceAttributes.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ResourceAttributes.java 29 Aug 2004 16:46:15 -0000 1.5
+++ ResourceAttributes.java 20 Apr 2005 16:13:23 -0000 1.6
@@ -753,6 +753,18 @@
}
+ /**
+ * Return the canonical path of the resource, to possibly be used for
+ * direct file serving. Implementations which support this should override
+ * it to return the file path.
+ *
+ * @return The canonical path of the resource
+ */
+ public String getCanonicalPath() {
+ return null;
+ }
+
+
// ----------------------------------------------------- Attributes Methods
1.8 +21 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/FileDirContext.java
Index: FileDirContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/FileDirContext.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FileDirContext.java 28 Jul 2004 20:27:01 -0000 1.7
+++ FileDirContext.java 20 Apr 2005 16:13:23 -0000 1.8
@@ -997,6 +997,9 @@
protected boolean accessed = false;
+ protected String canonicalPath = null;
+
+
// ----------------------------------------- ResourceAttributes Methods
@@ -1102,6 +1105,23 @@
return super.getResourceType();
}
+
+ /**
+ * Get canonical path.
+ *
+ * @return String the file's canonical path
+ */
+ public String getCanonicalPath() {
+ if (canonicalPath == null) {
+ try {
+ canonicalPath = file.getCanonicalPath();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ return canonicalPath;
+ }
+
}
1.2 +0 -1 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalAprOutputBuffer.java
Index: InternalAprOutputBuffer.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalAprOutputBuffer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InternalAprOutputBuffer.java 14 Apr 2005 18:52:28 -0000 1.1
+++ InternalAprOutputBuffer.java 20 Apr 2005 16:13:23 -0000 1.2
@@ -20,7 +20,6 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
-import org.apache.tomcat.jni.Error;
import org.apache.tomcat.jni.Socket;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.buf.CharChunk;
1.8 +34 -2 jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11AprProcessor.java
Index: Http11AprProcessor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/Http11AprProcessor.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Http11AprProcessor.java 18 Apr 2005 16:47:47 -0000 1.7
+++ Http11AprProcessor.java 20 Apr 2005 16:13:23 -0000 1.8
@@ -158,6 +158,12 @@
/**
+ * Sendfile data.
+ */
+ protected AprEndpoint.SendfileData sendfileData = null;
+
+
+ /**
* Content delimitator for the request (if false, the connection will
* be closed at the end of the request).
*/
@@ -753,7 +759,7 @@
// Parsing the request header
try {
if( !disableUploadTimeout && keptAlive && soTimeout > 0 ) {
- Socket.timeoutSet(socket, soTimeout);
+ Socket.timeoutSet(socket, soTimeout * 1000);
}
if (!inputBuffer.parseRequestLine()) {
// This means that no data is available right now
@@ -769,7 +775,7 @@
thrA.setParam(endpoint, request.requestURI());
keptAlive = true;
if (!disableUploadTimeout) {
- Socket.timeoutSet(socket, timeout);
+ Socket.timeoutSet(socket, timeout * 1000);
}
inputBuffer.parseHeaders();
} catch (IOException e) {
@@ -864,6 +870,13 @@
inputBuffer.nextRequest();
outputBuffer.nextRequest();
+ // Do sendfile as needed: add socket to sendfile and end
+ if (sendfileData != null) {
+ keepAlive = false;
+ sendfileData.pool = pool;
+ endpoint.getSendfile().add(socket, sendfileData);
+ }
+
}
rp.setStage(org.apache.coyote.Constants.STAGE_ENDED);
@@ -1141,6 +1154,7 @@
http09 = false;
contentDelimitation = false;
expectation = false;
+ sendfileData = null;
if (sslSupport != null) {
request.scheme().setString("https");
}
@@ -1307,6 +1321,11 @@
if (!contentDelimitation)
keepAlive = false;
+ // Advertise sendfile support through a request attribute
+ if (endpoint.getUseSendfile()) {
+ request.setAttribute("sendfile.support", Boolean.TRUE);
+ }
+
}
@@ -1483,6 +1502,19 @@
contentDelimitation = true;
}
+ // Sendfile support
+ String fileName = (String) request.getAttribute("sendfile.filename");
+ if (fileName != null) {
+ // No entity body sent here
+ outputBuffer.addActiveFilter
+ (outputFilters[Constants.VOID_FILTER]);
+ contentDelimitation = true;
+ sendfileData = new AprEndpoint.SendfileData();
+ sendfileData.fileName = fileName;
+ sendfileData.start = ((Long) request.getAttribute("sendfile.start")).longValue();
+ sendfileData.end = ((Long) request.getAttribute("sendfile.end")).longValue();
+ }
+
// Check for compression
boolean useCompression = false;
if (entityBody && (compressionLevel > 0)) {
1.14 +9 -1 jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/AprEndpoint.java
Index: AprEndpoint.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/net/AprEndpoint.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- AprEndpoint.java 20 Apr 2005 00:13:24 -0000 1.13
+++ AprEndpoint.java 20 Apr 2005 16:13:23 -0000 1.14
@@ -282,6 +282,14 @@
/**
+ * Use endfile for sending static files.
+ */
+ protected boolean useSendfile = false;
+ public void setUseSendfile(boolean useSendfile) { this.useSendfile = useSendfile; }
+ public boolean getUseSendfile() { return useSendfile; }
+
+
+ /**
* Number of keepalive sockets.
*/
protected int keepAliveCount = 0;
@@ -546,7 +554,7 @@
if (tcpNoDelay)
Socket.optSet(socket, Socket.APR_TCP_NODELAY, (tcpNoDelay ? 1 : 0));
if (soTimeout > 0)
- Socket.timeoutSet(socket, soTimeout);
+ Socket.timeoutSet(socket, soTimeout * 1000);
}
1.22 +6 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/connector/Request.java
Index: Request.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/connector/Request.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- Request.java 1 Apr 2005 11:36:52 -0000 1.21
+++ Request.java 20 Apr 2005 16:13:23 -0000 1.22
@@ -1366,6 +1366,11 @@
replaced = true;
}
+ // Pass special attributes to the native layer
+ if (name.startsWith("sendfile.")) {
+ coyoteRequest.setAttribute(name, value);
+ }
+
// Notify interested application event listeners
Object listeners[] = context.getApplicationEventListeners();
if ((listeners == null) || (listeners.length == 0))
1.32 +34 -3 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java
Index: DefaultServlet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets/DefaultServlet.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- DefaultServlet.java 18 Dec 2004 12:04:40 -0000 1.31
+++ DefaultServlet.java 20 Apr 2005 16:13:23 -0000 1.32
@@ -818,7 +818,8 @@
// Silent catch
}
if (ostream != null) {
- copy(cacheEntry, renderResult, ostream);
+ if (!checkSendfile(request, response, cacheEntry, contentLength, null))
+ copy(cacheEntry, renderResult, ostream);
} else {
copy(cacheEntry, renderResult, writer);
}
@@ -856,7 +857,8 @@
// Silent catch
}
if (ostream != null) {
- copy(cacheEntry, ostream, range);
+ if (!checkSendfile(request, response, cacheEntry, range.end - range.start + 1, range))
+ copy(cacheEntry, ostream, range);
} else {
copy(cacheEntry, writer, range);
}
@@ -1480,6 +1482,35 @@
/**
+ * Check if sendfile can be used.
+ */
+ private boolean checkSendfile(HttpServletRequest request,
+ HttpServletResponse response,
+ CacheEntry entry,
+ long length, Range range) {
+ if ((entry.resource != null)
+ && ((length > 256 * 1024) || (entry.resource.getContent() == null))
+ && (entry.attributes.getCanonicalPath() != null)
+ && (Boolean.TRUE == request.getAttribute("sendfile.support"))
+ && (request.getClass().getName().equals("org.apache.catalina.connector.RequestFacade"))
+ && (response.getClass().getName().equals("org.apache.catalina.connector.ResponseFacade"))) {
+ request.setAttribute("sendfile.filename", entry.attributes.getCanonicalPath());
+ if (range == null) {
+ request.setAttribute("sendfile.start", new Long(0L));
+ request.setAttribute("sendfile.end", new Long(length));
+ } else {
+ request.setAttribute("sendfile.start", new Long(range.start));
+ request.setAttribute("sendfile.end", new Long(range.end + 1));
+ }
+ request.setAttribute("sendfile.token", this);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+
+ /**
* Check if the if-match condition is satisfied.
*
* @param request The servlet request we are processing
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets
DefaultServlet.java
Posted by Remy Maucherat <re...@apache.org>.
Bill Barker wrote:
> I remember reading a while back on dev@httpd that there were some problems
> with sendfile on Windows. I don't remember the details, and I don't follow
> dev@apr to know if they have been fixed.
sendfile itself seems to work fine so far (I feed it with the canonical
path of the file), but however the %&ç$!!*ç% poller doesn't do what it
should be doing (hence my comment about a black magic API). I seems
blocking sendfiles would be working ok, but there are little benefits.
Rémy
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets DefaultServlet.java
Posted by Bill Barker <wb...@wilshire.com>.
----- Original Message -----
From: "Remy Maucherat" <re...@apache.org>
To: "Tomcat Developers List" <to...@jakarta.apache.org>
Sent: Wednesday, April 20, 2005 11:06 AM
Subject: Re: cvs commit:
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets
DefaultServlet.java
>Bill Barker wrote:
>> This should be 'org.apache.catalina.sendfile' (or, if you prefer,
>> 'org.apache.tomcat.sendfile'). Otherwise, you'll get BZ reports like:
>> <whine>
>> In my application Filter I do
>> request.setAttribute("sendfile.filename", new MySendFileName());
>> and my application breaks on 5.5.10. It worked fine on 5.5.9.
>> </whine>
>
>Well, I'll add a ckeck for the token to avoid this. It's completely
>broken anyway right now (Mladen says it can be fixed), so there's a
>chance that this feature will be scrapped.
>
I remember reading a while back on dev@httpd that there were some problems
with sendfile on Windows. I don't remember the details, and I don't follow
dev@apr to know if they have been fixed.
>Passing attributes to the lower layer is harmless (and I don't quite
>like huge names, but I can change them if you want to).
>
I don't care if you pass all attributes to the Coyote Request. It might
even be A Good Thing. It's just that if we follow the spec recommendation
in section 4.2, we can say that the 'org.apache.catalina' attribute name
space is reserved for Tomcat internal attributes. Reserving the 'sendfile'
namespace for Tomcat internals is rather arbitrary, and more likely to break
webapps.
>Rémy
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
This message is intended only for the use of the person(s) listed above as the intended recipient(s), and may contain information that is PRIVILEGED and CONFIDENTIAL. If you are not an intended recipient, you may not read, copy, or distribute this message or any attachment. If you received this communication in error, please notify us immediately by e-mail and then delete all copies of this message and any attachments.
In addition you should be aware that ordinary (unencrypted) e-mail sent through the Internet is not secure. Do not send confidential or sensitive information, such as social security numbers, account numbers, personal identification numbers and passwords, to us via ordinary (unencrypted) e-mail.
Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets
DefaultServlet.java
Posted by Remy Maucherat <re...@apache.org>.
Bill Barker wrote:
> This should be 'org.apache.catalina.sendfile' (or, if you prefer,
> 'org.apache.tomcat.sendfile'). Otherwise, you'll get BZ reports like:
> <whine>
> In my application Filter I do
> request.setAttribute("sendfile.filename", new MySendFileName());
> and my application breaks on 5.5.10. It worked fine on 5.5.9.
> </whine>
Well, I'll add a ckeck for the token to avoid this. It's completely
broken anyway right now (Mladen says it can be fixed), so there's a
chance that this feature will be scrapped.
Passing attributes to the lower layer is harmless (and I don't quite
like huge names, but I can change them if you want to).
Rémy
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets DefaultServlet.java
Posted by Bill Barker <wb...@wilshire.com>.
----- Original Message -----
From: <re...@apache.org>
To: <ja...@apache.org>
Sent: Wednesday, April 20, 2005 9:13 AM
Subject: cvs commit:
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/servlets
DefaultServlet.java
> remm 2005/04/20 09:13:23
>
> Modified: catalina/src/share/org/apache/naming/resources
> ResourceAttributes.java FileDirContext.java
> http11/src/java/org/apache/coyote/http11
> InternalAprOutputBuffer.java
> Http11AprProcessor.java
> util/java/org/apache/tomcat/util/net AprEndpoint.java
> catalina/src/share/org/apache/catalina/connector
> Request.java
> catalina/src/share/org/apache/catalina/servlets
> DefaultServlet.java
> Log:
> - Fix setting timeouts on sockets.
> - Add plumbing code for sendfile (disabled by default), which doesn't
work yet.
> - Apparently, the Sendfile.run algo is bad. APR is black magic to me, so
I'll let Mladen fix it :)
>
<snip/>
>
> + // Pass special attributes to the native layer
> + if (name.startsWith("sendfile.")) {
> + coyoteRequest.setAttribute(name, value);
> + }
> +
This should be 'org.apache.catalina.sendfile' (or, if you prefer,
'org.apache.tomcat.sendfile'). Otherwise, you'll get BZ reports like:
<whine>
In my application Filter I do
request.setAttribute("sendfile.filename", new MySendFileName());
and my application breaks on 5.5.10. It worked fine on 5.5.9.
</whine>
This message is intended only for the use of the person(s) listed above as the intended recipient(s), and may contain information that is PRIVILEGED and CONFIDENTIAL. If you are not an intended recipient, you may not read, copy, or distribute this message or any attachment. If you received this communication in error, please notify us immediately by e-mail and then delete all copies of this message and any attachments.
In addition you should be aware that ordinary (unencrypted) e-mail sent through the Internet is not secure. Do not send confidential or sensitive information, such as social security numbers, account numbers, personal identification numbers and passwords, to us via ordinary (unencrypted) e-mail.