Re: cvs commit: jakarta-tomcat-4.1/catalina/src/share/org/apache/catalina/connector/http SocketInputStream.java

2001-01-12 Thread Thomas Butter

[EMAIL PROTECTED] wrote:

 remm01/01/11 22:51:58
 
   Modified:catalina/src/share/org/apache/catalina/connector/http
 SocketInputStream.java
   Log:
   - Merge with some code inspired from code from BufferedInputStream.
   - Removed some unnecessary synchronization (to be confirmed). If the
 sync was necessary, I suggest doing it in the RequestInputStream.read()
 instead.
   
 
 */
   -public class SocketInputStream extends BufferedInputStream {
   +public class SocketInputStream extends InputStream {


I think you should subclass FilterInputStream, because it will provide 
you default implementations for the read(xxx) methods by calling the 
read() method.

-- 
Thomas Butter [EMAIL PROTECTED]  ICQ: 891617

"Unix IS user friendly, it is just selective about who his friends are."


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]




Re: possible problems in org.apache.catalina.connector.http.SocketInputStream

2001-01-11 Thread Thomas Butter

Remy Maucherat wrote:

 
 I can't see why. Is my interpretation on what will happen at the next
 iteration wrong ?
 
You are perfectly right. Sorry, I misunderstood the loop (didn't realize 
the pos=0 after the read()).

A problem could only arrise if somewhere else a mark is set before your 
functions, then pos=0 would set the wrong position. But marks are not 
used anywhere so this won't be a problem.

 
 Especially since we don't care about marking here.

I attached a little patch that reimplements the used methods of the BIS. 
It should be a little bit faster because it doesn't implement marks.
Not sure if it is worth the extra code because read() isn't called very 
often anyway and if read(byte []) is used anywhere then it should be 
rewritten too (didn't do it here because I wasn't sure if it is ever used).

-- 
Thomas Butter [EMAIL PROTECTED]  ICQ: 891617

"Unix IS user friendly, it is just selective about who his friends are."



--- SocketInputStream.java.orig Thu Jan 11 09:18:45 2001
+++ SocketInputStream.java  Thu Jan 11 10:14:41 2001
@@ -65,7 +65,7 @@
 package org.apache.catalina.connector.http;
 
 import java.io.IOException;
-import java.io.BufferedInputStream;
+import java.io.FilterInputStream;
 import java.io.InputStream;
 import java.io.EOFException;
 import org.apache.catalina.util.StringManager;
@@ -76,7 +76,7 @@
  *
  * @author a href="mailto:[EMAIL PROTECTED]"Remy Maucherat/a
  */
-public class SocketInputStream extends BufferedInputStream {
+public class SocketInputStream extends FilterInputStream {
 
 
 // -- Constants
@@ -112,8 +112,54 @@
 private static final int LC_OFFSET = 'A' - 'a';
 
 
-// --- Constructors
+// BufferInputStream rewrite without marks
 
+private byte buf[];
+private int count=0;
+private int pos=0;
+
+public void close() throws IOException {
+   if(in!=null) in.close();
+   in=null;
+   buf=null;
+}
+
+public synchronized int available() throws IOException {
+   if(in==null)
+   throw (new IOException("Stream was closed"));
+   return (count-pos)+in.available();
+}
+
+public synchronized int read()
+   throws IOException
+{
+   if(in==null)
+   throw (new IOException("Stream was closed"));
+   if(pos=count) {
+   pos=0;
+   count=in.read(buf);
+   if(count=0) return -1;
+   }
+
+   return buf[pos++]  0xff;
+}
+
+public synchronized long skip(long n) throws IOException {
+   if(in==null)
+   throw (new IOException("Stream was closed"));
+   long skipped=0;
+if(n=0) return 0;
+   if(ncount-pos) {
+   skipped=count-pos;
+   n-=skipped;
+   pos=count;
+   skipped+=in.skip(n);
+   } else {
+   skipped=n;
+   count+=n;
+   }
+   return skipped;
+}  
 
 /**
  * Construct a servlet input stream associated with the specified socket
@@ -123,9 +169,9 @@
  * @param bufferSize size of the internal buffer
  */
 public SocketInputStream(InputStream is, int bufferSize) {
-
-   super(is, bufferSize);
-
+   super(is);
+if(bufferSize=0) bufferSize=1024; // switch back to default
+buf=new byte[bufferSize];
 }
 
 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]


[PATCH] bind to ip

2001-01-10 Thread Thomas Butter

Sorry, I accidently send this to the user list before.



The current org.apache.catalina.connector.http.HttpConnector doesn't 
bind to a single ip if the hostname of the machine doesn't have a A 
record for the IP.

This breaks most Virtualserver enviroments that want to run different 
server (for example apache and tomcat) on the same machine.

The patch should solve this problem.


-- 
Thomas Butter [EMAIL PROTECTED]  ICQ: 891617

"Unix IS user friendly, it is just selective about who his friends are."


--- HttpConnector.java.orig Wed Jan 10 23:17:51 2001
+++ HttpConnector.java  Wed Jan 10 23:20:16 2001
@@ -734,17 +734,12 @@
}
 
// Open a server socket on the specified address
-   InetAddress[] addresses =
-   InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
-   int i;
-   for (i = 0; i  addresses.length; i++) {
-   if (addresses[i].getHostAddress().equals(address))
-   break;
-   }
-   if (i  addresses.length) {
+   try
+   {
+   InetAddress is=InetAddress.getByName(address);
log(sm.getString("httpConnector.anAddress", address));
 return (factory.createSocket(port, acceptCount, addresses[i]));
-   } else {
+   } catch(Exception e) {
log(sm.getString("httpConnector.noAddress", address));
 return (factory.createSocket(port, acceptCount));
}



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]


possible problems in org.apache.catalina.connector.http.SocketInputStream

2001-01-10 Thread Thomas Butter

SocketInputStream extends java.io.BufferedInputStream and uses the 
protected fields buf, pos and count.

As far as I can see there are several problems with some uses of pos:
First of all the use of buf and pos are not defined by the api, so it is 
theoretical implementation dependent.

Furthermore there are some problems even if the buf and pos are used in 
the original way:

For example if in line 257:   
   requestLine.uri[readCount] = (char) buf[pos];
   readCount++;
   pos++;

buf[pos] is undefined the last fill called by the last read() only got 
one byte (which was enough for the last read()).

There are several situations in the class where this problem could happen.

I think this class should be rewritten using PushbackInputStream (or 
better using a new PushbackInputStream(new BufferInputStream(in))).

I would volunteer rewriting this class if you agree with my assumptions.



-- 
Thomas Butter [EMAIL PROTECTED]  ICQ: 891617

"Unix IS user friendly, it is just selective about who his friends are."


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]