Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@jakarta.apache.org Received: (qmail 21049 invoked by uid 500); 14 Mar 2001 23:51:27 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: tomcat-dev@jakarta.apache.org Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 21004 invoked from network); 14 Mar 2001 23:51:21 -0000 Message-Id: X-Mailer: Novell GroupWise Internet Agent 5.5.5.1 Date: Wed, 14 Mar 2001 16:50:50 -0700 From: "Mike Anderson" To: Subject: The available method for ServletInputStream subclasses (tomcat_32 branch) Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_114A96F0.8EEFE6CE" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=_114A96F0.8EEFE6CE Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline In working with some internal groups, we have some classes that perform = file uploads (anyone heard of GroupWise Webaccess?). One of the things = they have done in their servlets that handle this is call the available = method on the ServletInputStream so that they can delay the thread for a = small amount of time if there isn't anything available to be read from the = socket. This allows the machine and other threads to do other processing, = and allows the thread that wants to read the data to gracefully handle a = client prematurely shutting down the connection. This functionality works = on other servlet engines (JServ, WebSphere, Novell Servlet Gateway) but = doesn't work on Tomcat because the available() method was never implemented= in any of the subclasses. So when availabe() is called, it just resolves = down to java.io.InputStream which is documented as returning 0 because = subclasses should override this method. There are 2 ways to fix this: 1. In BufferedServletInputStream, implement an available() method that = returns limit-bytesRead or 0 whichever is greater. The limit class = variable is set to the value of the Content-Length header and bytesRead is = the number of bytes read since limit was set. (See the attached patch). = This is the easy fix but doesn't address the feature of available that = says it will return the number of bytes that can be read "without = blocking". Obviously, if there is a large amount of data, a read will = most likely block at some point depending on how much is asked for. 2. Update BufferedServletInputStream to call reqA.available and then = update the following files to provide this interface: Request.java RequestImpl.java HttpRequestAdapter.java AJP12RequestAdapter.java Ajp13RequestAdapter.java JNIRequestAdapter.java Each of these classes would need to provide an appropriate available() = method. I'm willing to figure this out and implement #2 if it is deemed the better = approach and only provided #1 because it was a "quick" fix. I'm also = willing to figure this out for the 3.3 tree for either implementation. I = would like to get it into the 3.2.2 branch since that is what most of use = here are currently using. Any response (other than flames:-) appreciated. --=_114A96F0.8EEFE6CE Content-Type: application/octet-stream; name="diff.out" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="diff.out" SW5kZXg6IEJ1ZmZlcmVkU2VydmxldElucHV0U3RyZWFtLmphdmENCj09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0NClJDUyBm aWxlOiAvaG9tZS9jdnNwdWJsaWMvamFrYXJ0YS10b21jYXQvc3JjL3NoYXJlL29yZy9hcGFjaGUv dG9tY2F0L2NvcmUvQXR0aWMvQnVmZmVyZWRTZXJ2bGV0SW5wdXRTdHJlYW0uamF2YSx2DQpyZXRy aWV2aW5nIHJldmlzaW9uIDEuOA0KZGlmZiAtdSAtcjEuOCBCdWZmZXJlZFNlcnZsZXRJbnB1dFN0 cmVhbS5qYXZhDQotLS0gQnVmZmVyZWRTZXJ2bGV0SW5wdXRTdHJlYW0uamF2YQkyMDAwLzA1LzI2 IDE3OjMyOjA0CTEuOA0KKysrIEJ1ZmZlcmVkU2VydmxldElucHV0U3RyZWFtLmphdmEJMjAwMS8w My8xNCAyMzoxODo0NQ0KQEAgLTE1MSw2ICsxNTEsMTEgQEANCiAJfQ0KICAgICB9DQogICAgIA0K KyAgICBwdWJsaWMgaW50IGF2YWlsYWJsZSgpIHRocm93cyBJT0V4Y2VwdGlvbg0KKyAgICB7DQor ICAgICAgICByZXR1cm4gTWF0aC5tYXgoKGxpbWl0IC0gYnl0ZXNSZWFkKSwgMCk7DQorICAgIH0N CisgICAgDQogDQogLy8gICAgIC8qKg0KIC8vICAgICAgKiBAZGVwcmVjYXRlZCBOb3QgcGFydCBv ZiBTZXJ2bGV0IEFQSSwgd2l0aG91dCBpdCB3ZSBjYW4gYXZvaWQgYSBsb3Qgb2YgR0MuDQo= --=_114A96F0.8EEFE6CE--