tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@locus.apache.org
Subject cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/util/net DefaultServerSocketFactory.java PoolTcpEndpoint.java SSLSocketFactory.java ServerSocketFactory.java TcpConnection.java TcpConnectionHandler.java
Date Mon, 14 Aug 2000 21:54:39 GMT
costin      00/08/14 14:54:38

  Modified:    src/etc  server.xml
               src/share/org/apache/tomcat/core Request.java
               src/share/org/apache/tomcat/service PoolTcpConnector.java
               src/share/org/apache/tomcat/service/connector
                        Ajp12ConnectionHandler.java
                        Ajp13ConnectionHandler.java
               src/share/org/apache/tomcat/service/http
                        HttpConnectionHandler.java HttpInterceptor.java
               src/share/org/apache/tomcat/util DateTool.java Reaper.java
                        RequestUtil.java
  Added:       src/share/org/apache/tomcat/util/net
                        DefaultServerSocketFactory.java
                        PoolTcpEndpoint.java SSLSocketFactory.java
                        ServerSocketFactory.java TcpConnection.java
                        TcpConnectionHandler.java
  Removed:     src/share/org/apache/tomcat/net
                        DefaultServerSocketFactory.java
                        SSLSocketFactory.java ServerSocketFactory.java
               src/share/org/apache/tomcat/service PoolTcpEndpoint.java
                        TcpConnection.java TcpConnectionHandler.java
  Log:
  More cosmetic changes: moved the net code in tomcat.util.net.
  That includes SocketFactory code and the TcpConnection code.
  The code needs more work - explicit setters instead of
  setAttribute, etc.
  
  The goal is to improve code organization in tomcat:
  org.apache.tomcat.util will contain generic utilities
  and all tomcat-dependend code will be in org.apache.tomcat.*
  ( probably we should use org.apache.auc instead of tomcat.util )
  Each component in util can be used stand-alone and
  we can remove a number of hacks ( like setAttribute )
  
  - added more code to HttpInterceptor.
  - removed more unused code
  
  Revision  Changes    Path
  1.36      +13 -1     jakarta-tomcat/src/etc/server.xml
  
  Index: server.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/etc/server.xml,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- server.xml	2000/08/14 17:49:08	1.35
  +++ server.xml	2000/08/14 21:54:09	1.36
  @@ -95,6 +95,18 @@
            ContextInterceptor className="org.apache.tomcat.context.LogEvents" 
            -->
           
  +        <!-- new http adapter. Attributes:
  +                secure - use SSL ( https )
  +                keystore, keypass - certs for SSL
  +                port
  +                XXX not finished, more attributes will come to match the current 
  +                functionality
  +         -->
  +        <ContextInterceptor className="org.apache.tomcat.service.http.HttpInterceptor"
  +                            port="8081"
  +                            secure="false"
  +         />
  +
           <ContextInterceptor className="org.apache.tomcat.context.AutoSetup" />
   
           <ContextInterceptor 
  @@ -226,7 +238,7 @@
               <Parameter name="port" 
                   value="8443"/>
               <Parameter name="socketFactory" 
  -                value="org.apache.tomcat.net.SSLSocketFactory" />
  +                value="org.apache.tomcat.util.net.SSLSocketFactory" />
           </Connector>
           -->
   
  
  
  
  1.52      +0 -8      jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
  
  Index: Request.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- Request.java	2000/08/12 04:55:45	1.51
  +++ Request.java	2000/08/14 21:54:11	1.52
  @@ -690,14 +690,6 @@
       }
   
       // -------------------- Utils - facade for RequestUtil
  -    /** @deprecated
  -     */
  -    public BufferedReader getReader()
  -	throws IOException
  -    {
  -	return RequestUtil.getReader( this );
  -    }
  -
       private void handleParameters() {
      	if(!didParameters) {
   	    String qString=getQueryString();
  
  
  
  1.13      +1 -1      jakarta-tomcat/src/share/org/apache/tomcat/service/PoolTcpConnector.java
  
  Index: PoolTcpConnector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/PoolTcpConnector.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PoolTcpConnector.java	2000/08/11 16:24:24	1.12
  +++ PoolTcpConnector.java	2000/08/14 21:54:19	1.13
  @@ -62,7 +62,7 @@
   
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.core.*;
  -import org.apache.tomcat.net.*;
  +import org.apache.tomcat.util.net.*;
   import org.apache.tomcat.logging.*;
   import java.io.*;
   import java.net.*;
  
  
  
  1.34      +1 -0      jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java
  
  Index: Ajp12ConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- Ajp12ConnectionHandler.java	2000/08/12 04:55:47	1.33
  +++ Ajp12ConnectionHandler.java	2000/08/14 21:54:23	1.34
  @@ -69,6 +69,7 @@
   import java.net.*;
   import java.util.*;
   import org.apache.tomcat.core.*;
  +import org.apache.tomcat.util.net.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.logging.*;
   import org.apache.tomcat.service.http.*;
  
  
  
  1.6       +4 -3      jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectionHandler.java
  
  Index: Ajp13ConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectionHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Ajp13ConnectionHandler.java	2000/07/11 03:48:55	1.5
  +++ Ajp13ConnectionHandler.java	2000/08/14 21:54:24	1.6
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectionHandler.java,v 1.5 2000/07/11 03:48:55 alex Exp $
  - * $Revision: 1.5 $
  - * $Date: 2000/07/11 03:48:55 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp13ConnectionHandler.java,v 1.6 2000/08/14 21:54:24 costin Exp $
  + * $Revision: 1.6 $
  + * $Date: 2000/08/14 21:54:24 $
    *
    * ====================================================================
    *
  @@ -69,6 +69,7 @@
   import java.net.*;
   import java.util.*;
   import org.apache.tomcat.core.*;
  +import org.apache.tomcat.util.net.*;
   import org.apache.tomcat.util.*;
   import org.apache.tomcat.logging.*;
   import javax.servlet.*;
  
  
  
  1.30      +4 -3      jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java
  
  Index: HttpConnectionHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- HttpConnectionHandler.java	2000/08/12 02:46:48	1.29
  +++ HttpConnectionHandler.java	2000/08/14 21:54:27	1.30
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v 1.29 2000/08/12 02:46:48 costin Exp $
  - * $Revision: 1.29 $
  - * $Date: 2000/08/12 02:46:48 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v 1.30 2000/08/14 21:54:27 costin Exp $
  + * $Revision: 1.30 $
  + * $Date: 2000/08/14 21:54:27 $
    *
    * ====================================================================
    *
  @@ -70,6 +70,7 @@
   import java.util.*;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.*;
  +import org.apache.tomcat.util.net.*;
   import org.apache.tomcat.logging.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  
  
  
  1.2       +44 -6     jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpInterceptor.java
  
  Index: HttpInterceptor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpInterceptor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpInterceptor.java	2000/08/14 20:48:11	1.1
  +++ HttpInterceptor.java	2000/08/14 21:54:27	1.2
  @@ -66,7 +66,8 @@
   import java.util.*;
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.*;
  -import org.apache.tomcat.net.*;
  +import org.apache.tomcat.util.net.*;
  +import org.apache.tomcat.util.net.ServerSocketFactory;
   import org.apache.tomcat.logging.*;
   import javax.servlet.*;
   import javax.servlet.http.*;
  @@ -87,19 +88,24 @@
    *  - maxSpareThreads
    *  - maxThreads
    *  - poolOn
  - * Extra properties:
  - *  - serverSocketFactory ( default simple tcp, shortcut: ssl ). Overrides "secure"
  + * Properties for HTTPS:
  + *  - keystore - certificates - default to ~/.keystore
  + *  - keypass - password
  + *  - clientauth - true if the server should authenticate the client using certs
    */
   public class HttpInterceptor extends BaseInterceptor  implements  TcpConnectionHandler {
  +    boolean enabled=true;
  +
       // Tcp stuff
       PoolTcpEndpoint ep;
       private ServerSocketFactory socketFactory;
  -    private ServerSocket serverSocket;
   
       // properties
       int port;
       InetAddress address;
  -
  +    String keystore;
  +    String keypass;
  +    
       
       boolean secure=false;
       ContextManager contextM;
  @@ -134,6 +140,8 @@
   	ep.setConnectionHandler( this );
   	try {
   	    ep.setPort( port );
  +	    if( socketFactory!=null )
  +		ep.setServerSocketFactory( socketFactory );
   	    ep.startEndpoint();
   	    log( "Starting on " + port );
   	} catch( Exception ex ) {
  @@ -152,9 +160,39 @@
   
   
       // -------------------- Attributes --------------------
  +    public void setKeystore( String k ) {
  +	keystore=k;
  +    }
  +    public void getKeystore() {
  +	return keystore;
  +    }
       
       public void setSecure( boolean b ) {
  -	secure=b;
  +	enabled=false;
  +	secure=false;
  +	if( b == true ) {
  +	    if( keystore!=null && ! new File( keystore ).exists() ) {
  +		log("Can't find keystore " + keystore );
  +		return;
  +	    }
  +	    try {
  +		Class c1=Class.forName( "javax.net.ssl.SSLServerSocketFactory");
  +	    } catch( Exception ex ) {
  +		log( "Can't find JSSE, HTTPS will not be enabled");
  +		return;
  +	    }
  +	    try {
  +		Class chC=Class.forName( "org.apache.tomcat.util.net.SSLSocketFactory" );
  +		socketFactory=(ServerSocketFactory)chC.newInstance();
  +		if( keystore!=null)
  +		    socketFactory.setAttribute( "keystore", keystore);
  +	    } catch(Exception ex ) {
  +		log( "Error loading SSL socket factory ", ex);
  +		return;
  +	    }
  +	}
  +    	secure=b;
  +	enabled=true;
       }
   
       // -------------------- Handler implementation --------------------
  
  
  
  1.5       +3 -4      jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java
  
  Index: DateTool.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DateTool.java	2000/08/11 06:14:18	1.4
  +++ DateTool.java	2000/08/14 21:54:31	1.5
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v 1.4 2000/08/11 06:14:18 costin Exp $
  - * $Revision: 1.4 $
  - * $Date: 2000/08/11 06:14:18 $
  + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/DateTool.java,v 1.5 2000/08/14 21:54:31 costin Exp $
  + * $Revision: 1.5 $
  + * $Date: 2000/08/14 21:54:31 $
    *
    * ====================================================================
    *
  @@ -68,7 +68,6 @@
   import java.io.OutputStream;
   import java.util.*;
   import java.text.*;
  -import org.apache.tomcat.core.Constants;
   
   /**
    *  Common place for date utils.
  
  
  
  1.4       +0 -1      jakarta-tomcat/src/share/org/apache/tomcat/util/Reaper.java
  
  Index: Reaper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Reaper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Reaper.java	2000/05/26 23:55:55	1.3
  +++ Reaper.java	2000/08/14 21:54:31	1.4
  @@ -60,7 +60,6 @@
   
   package org.apache.tomcat.util;
   
  -import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.*;
   
   /**
  
  
  
  1.18      +0 -17     jakarta-tomcat/src/share/org/apache/tomcat/util/RequestUtil.java
  
  Index: RequestUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/RequestUtil.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- RequestUtil.java	2000/07/29 18:44:05	1.17
  +++ RequestUtil.java	2000/08/14 21:54:32	1.18
  @@ -148,23 +148,6 @@
   	return combined;
       }
   
  -    /** @deprecated
  -     */
  -    public static BufferedReader getReader(Request request) throws IOException {
  -        // XXX
  -	// this won't work in keep alive scenarios. We need to provide
  -	// a buffered reader that won't try to read in the stream
  -	// past the content length -- if we don't, the buffered reader
  -	// will probably try to read into the next request... bad!
  -        String encoding = request.getCharacterEncoding();
  -        if (encoding == null) {
  -            encoding = Constants.DEFAULT_CHAR_ENCODING;
  -        }
  -	InputStreamReader r =
  -            new InputStreamReader(request.getInputStream(), encoding);
  -	return new BufferedReader(r);
  -    }
  -
       public static void processCookies( Request request, Vector cookies ) {
   	// XXX bug in original RequestImpl - might not work if multiple
   	// cookie headers.
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/net/DefaultServerSocketFactory.java
  
  Index: DefaultServerSocketFactory.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/net/DefaultServerSocketFactory.java,v 1.1 2000/08/14 21:54:36 costin Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/14 21:54:36 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.tomcat.util.net;
  
  import java.io.*;
  import java.net.*;
  
  /**
   * Default server socket factory. Doesn't do much except give us
   * plain ol' server sockets.
   *
   * @author db@eng.sun.com
   * @author Harish Prabandham
   */
  
  // Default implementation of server sockets.
  
  //
  // WARNING: Some of the APIs in this class are used by J2EE. 
  // Please talk to harishp@eng.sun.com before making any changes.
  //
  class DefaultServerSocketFactory extends ServerSocketFactory {
  
      DefaultServerSocketFactory () {
          /* NOTHING */
      }
  
      public ServerSocket createSocket (int port)
      throws IOException {
          return  new ServerSocket (port);
      }
  
      public ServerSocket createSocket (int port, int backlog)
      throws IOException {
          return new ServerSocket (port, backlog);
      }
  
      public ServerSocket createSocket (int port, int backlog,
          InetAddress ifAddress)
      throws IOException {
          return new ServerSocket (port, backlog, ifAddress);
      }
  }
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/net/PoolTcpEndpoint.java
  
  Index: PoolTcpEndpoint.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/net/PoolTcpEndpoint.java,v 1.1 2000/08/14 21:54:37 costin Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/14 21:54:37 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.tomcat.util.net;
  
  import org.apache.tomcat.util.*;
  import org.apache.tomcat.logging.*;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  
  /* Similar with MPM module in Apache2.0. Handles all the details related with
     "tcp server" functionality - thread management, accept policy, etc.
     It should do nothing more - as soon as it get a socket ( and all socket options
     are set, etc), it just handle the stream to ConnectionHandler.processConnection. (costin)
  */
  
  
  
  /**
   * Handle incoming TCP connections.
   *
   * This class implement a simple server model: one listener thread accepts on a socket and
   * creates a new worker thread for each incoming connection.
   *
   * More advanced Endpoints will reuse the threads, use queues, etc.
   *
   * @author James Duncan Davidson [duncan@eng.sun.com]
   * @author Jason Hunter [jch@eng.sun.com]
   * @author James Todd [gonzo@eng.sun.com]
   * @author Costin@eng.sun.com
   * @author Gal Shachor [shachor@il.ibm.com]
   */
  public class PoolTcpEndpoint extends Logger.Helper  { // implements Endpoint {
  
      private StringManager sm = StringManager.getManager("org.apache.tomcat.resources");
  
      private static final int BACKLOG = 100;
      private static final int TIMEOUT = 1000;
  
      private boolean isPool = true;
  
      private int backlog = BACKLOG;
      private int timeout = TIMEOUT;
  
      TcpConnectionHandler handler;
  
      private InetAddress inet;
      private int port;
  
      private ServerSocketFactory factory;
      private ServerSocket serverSocket;
  
      ThreadPoolRunnable listener;
      private boolean running = false;
      static final int debug=0;
  
      ThreadPool tp;
  
      public PoolTcpEndpoint() {
  	super("tc_log");	// initialize default logger
  	tp = new ThreadPool();
      }
      
      // -------------------- Configuration --------------------
  
      public void setPoolOn(boolean isPool) {
          this.isPool = isPool;
      }
  
      public boolean isPoolOn() {
          return isPool;
      }
  
      public void setMaxThreads(int maxThreads) {
          tp.setMaxThreads(maxThreads);
      }
  
      public int getMaxThreads() {
          return tp.getMaxThreads();
      }
  
      public void setMaxSpareThreads(int maxThreads) {
          tp.setMaxSpareThreads(maxThreads);
      }
  
      public int getMaxSpareThreads() {
          return tp.getMaxSpareThreads();
      }
  
      public void setMinSpareThreads(int minThreads) {
          tp.setMinSpareThreads(minThreads);
      }
  
      public int getMinSpareThreads() {
          return tp.getMinSpareThreads();
      }
  
      public int getPort() {
  	    return port;
      }
  
      public void setPort(int port ) {
  	    this.port=port;
      }
  
      public InetAddress getAddress() {
  	    return inet;
      }
  
      public void setAddress(InetAddress inet) {
  	    this.inet=inet;
      }
  
      public void setServerSocket(ServerSocket ss) {
  	    serverSocket = ss;
      }
  
      public void setServerSocketFactory(  ServerSocketFactory factory ) {
  	    this.factory=factory;
      }
  
      public void setConnectionHandler( TcpConnectionHandler handler ) {
      	this.handler=handler;
      }
  
      public TcpConnectionHandler getConnectionHandler() {
  	    return handler;
      }
  
      public boolean isRunning() {
  	return running;
      }
      
      /**
       * Allows the server developer to specify the backlog that
       * should be used for server sockets. By default, this value
       * is 100.
       */
      public void setBacklog(int backlog) {
  	    this.backlog = backlog;
      }
  
      public int getBacklog() {
          return backlog;
      }
  
      /**
       * Sets the timeout in ms of the server sockets created by this
       * server. This method allows the developer to make servers
       * more or less responsive to having their server sockets
       * shut down.
       *
       * <p>By default this value is 1000ms.
       */
      public void setTimeout(int timeout) {
  	    this.timeout = timeout;
      }
  
      // -------------------- Public methods --------------------
  
      public void startEndpoint() throws IOException, InstantiationException {
  	try {
  	    if(factory==null)
  		factory=ServerSocketFactory.getDefault();
  	    if(serverSocket==null) {
  		if (inet == null) {
  		    serverSocket = factory.createSocket(port, backlog);
  		} else {
  		    serverSocket = factory.createSocket(port, backlog, inet);
  		}
  	    }
  	} catch( IOException ex ) {
  	    //	    log("couldn't start endpoint", ex, Logger.DEBUG);
              throw ex;
  	} catch( InstantiationException ex1 ) {
  	    //	    log("couldn't start endpoint", ex1, Logger.DEBUG);
              throw ex1;
  	}
  	if(isPool) {
  	    tp.start();
  	}
  	running = true;
          if(isPool) {
      	    listener = new TcpWorkerThread(this);
              tp.runIt(listener);
          } else {
  	    log("XXX Error - need pool !", null, Logger.ERROR);
  	}
      }
  
      public void stopEndpoint() {
  	log("Stopping endpoint");
  	if (running) {
  	    log("Stack trace that called stopEndpoint():", new Throwable("trace"), Logger.DEBUG);
  	    tp.shutdown();
  	    running = false;
  	    try {
  		serverSocket.close(); // XXX?
  	    } catch(Exception e) {
  	    }
  	    serverSocket = null;
  	}
      }
  
      // -------------------- Private methods
  
      Socket acceptSocket() {
          Socket accepted = null;
      	try {
      	    if (running) {
  		if(null!= serverSocket) {
  		    accepted = serverSocket.accept();
  		    if(running == false) {
  			if(null != accepted) {
  			    accepted.close();  // rude, but unlikely!
  			    accepted = null;
  			}
  		    }
  		    if( factory != null && accepted != null)
  			factory.initSocket( accepted );
      	        }
      	    }	    
      	}
  	catch(InterruptedIOException iioe) {
      	    // normal part -- should happen regularly so
      	    // that the endpoint can release if the server
      	    // is shutdown.
      	}
  	catch (SocketException e) {
  
  	    // TCP stacks can throw SocketExceptions when the client
  	    // disconnects.  We don't want this to shut down the
  	    // endpoint, so ignore it. Is there a more robust
  	    // solution?  Should we compare the message string to
  	    // "Connection reset by peer"?
  
  	    // socket exceptions just after closing endpoint (when
  	    // running=false) aren't even logged
      	    if (running != false) {
  		String msg = sm.getString("endpoint.err.nonfatal",
  					  serverSocket, e);
  		log(msg, e, Logger.INFORMATION);
      	    }
  
      	} 
  	
  	// Future developers: if you identify any other nonfatal
  	// exceptions, catch them here and log as above
  
  	catch(Throwable e) {
              // If we are running with a SecurityManager, don't shutdown Socket        
              // on an AccessControlException.
  	    if( e.getClass().getName().equals("java.security.AccessControlException") ) {
  		String msg = "Socket: "+ serverSocket + " AccessControlException: " + e.toString();
  		log(msg, Logger.ERROR);
  	    } else {
  		String msg = sm.getString("endpoint.err.fatal",
  					serverSocket, e);    
  		log(msg, e, Logger.ERROR);
  		stopEndpoint();	// safe to call this from inside thread pool?
  	    }
      	}
  
      	return accepted;
      }
  }
  
  // -------------------- Threads --------------------
  
  /*
   * I switched the threading model here.
   *
   * We used to have a "listener" thread and a "connection"
   * thread, this results in code simplicity but also a needless
   * thread switch.
   *
   * Instead I am now using a pool of threads, all the threads are
   * simmetric in their execution and no thread switch is needed.
   */
  class TcpWorkerThread implements ThreadPoolRunnable {
      /* This is not a normal Runnable - it gets attached to an existing
         thread, runs and when run() ends - the thread keeps running.
  
         It's better to keep the name ThreadPoolRunnable - avoid confusion.
         We also want to use per/thread data and avoid sync wherever possible.
      */
      PoolTcpEndpoint endpoint;
      SimplePool connectionCache;
      static final boolean usePool=true;
      
      public TcpWorkerThread(PoolTcpEndpoint endpoint) {
  	this.endpoint = endpoint;
  	if( usePool ) {
  	    connectionCache = new SimplePool(endpoint.getMaxThreads());
  	    for(int i = 0 ; i < endpoint.getMaxThreads()/2 ; i++) {
  		connectionCache.put(new TcpConnection());
  	    }
  	}
      }
  
      public Object[] getInitData() {
  	if( usePool ) {
  	    return endpoint.getConnectionHandler().init();
  	} else {
  	    // no synchronization overhead, but 2 array access 
  	    Object obj[]=new Object[2];
  	    obj[1]= endpoint.getConnectionHandler().init();
  	    obj[0]=new TcpConnection();
  	    return obj;
  	}
      }
      
      public void runIt(Object perThrData[]) {
  	TcpConnection con=null;
  	if( ! usePool ) {
  	    // extract the original.
  	    con=(TcpConnection) perThrData[0];
  	    perThrData = (Object []) perThrData[1];
  	}
  	
  	// Create per-thread cache
  	while(endpoint.isRunning()) {
  	    Socket s = endpoint.acceptSocket();
  	    if(null != s) {
  		// Continue accepting on another thread...
  		endpoint.tp.runIt(this);
  		
  		try {
  		    if( usePool ) {
  			con=(TcpConnection)connectionCache.get();
  			if( con == null ) 
  			    con = new TcpConnection();
  		    }
  		    
  		    con.setEndpoint(endpoint);
  		    con.setSocket(s);
  		    endpoint.getConnectionHandler().processConnection(con, perThrData);
                  } finally {
                      con.recycle();
                      if( usePool && con != null ) connectionCache.put(con);
                  }
                  break;
  	    }
  	}
      }
  }
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/net/SSLSocketFactory.java
  
  Index: SSLSocketFactory.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  package org.apache.tomcat.util.net;
  
  import java.io.*;
  import java.net.*;
  
  import java.security.KeyStore;
  
  import java.security.Security;
  import javax.net.ServerSocketFactory;
  import javax.net.ssl.SSLServerSocket;
  import javax.net.ssl.SSLSocket;
  import javax.net.ssl.SSLServerSocketFactory;
  import javax.net.ssl.HandshakeCompletedListener;
  import javax.net.ssl.HandshakeCompletedEvent;
  
  /*
    1. Add Jsse's jars into jre/lib/ext
    2. Edit java.security, add
         security.provider.2=com.sun.net.ssl.internal.ssl.Provider
    3. keytool -genkey -alias tomcat -keyalg RSA
       Use "changeit" as password ( this is the default we use )
   */
  
  /**
   * SSL server socket factory. It _requires_ a valid RSA key and
   * JSSE. 
   *
   * @author Harish Prabandham
   * @author Costin Manolache
   */
  public class SSLSocketFactory
      extends org.apache.tomcat.util.net.ServerSocketFactory
  {
      private String keystoreType;
  
      static String defaultKeystoreType = "JKS";
      static String defaultProtocol = "TLS";
      static String defaultAlgorithm = "SunX509";
      static boolean defaultClientAuth = false;
  
      private boolean clientAuth = false;
      private SSLServerSocketFactory sslProxy = null;
      
      // defaults
      static String defaultKeystoreFile=System.getProperty("user.home") +
  	"/.keystore";
      static String defaultKeyPass="changeit";
  
      
      public SSLSocketFactory () {
      }
  
      public ServerSocket createSocket (int port)
  	throws IOException
      {
  	if( sslProxy == null ) initProxy();
  	ServerSocket socket = 
  	    sslProxy.createServerSocket(port);
  	initServerSocket(socket);
  	return socket;
      }
      
      public ServerSocket createSocket (int port, int backlog)
  	throws IOException
      {
  	if( sslProxy == null ) initProxy();
  	ServerSocket socket = 
  	    sslProxy.createServerSocket(port, backlog);
  	initServerSocket(socket);
  	return socket;
      }
      
      public ServerSocket createSocket (int port, int backlog,
  				      InetAddress ifAddress)
  	throws IOException
      {	
  	if( sslProxy == null ) initProxy();
  	ServerSocket socket = 
  	    sslProxy.createServerSocket(port, backlog, ifAddress);
  	initServerSocket(socket);
  	return socket;
      }
      
      
      // -------------------- Internal methods
      /** Read the keystore, init the SSL socket factory
       */
      private void initProxy() throws IOException {
  	try {
  	    /** You should have this in java.security, but
  		can't hurt to double check
  	    */
  	    Security.addProvider (new sun.security.provider.Sun());
  	    Security.addProvider (new com.sun.net.ssl.internal.ssl.Provider());
  
  	    // Please don't change the name of the attribute - other
  	    // software may depend on it ( j2ee for sure )
  	    String keystoreFile=(String)attributes.get("keystore");
  	    if( keystoreFile==null) keystoreFile=defaultKeystoreFile;
  
  	    keystoreType=(String)attributes.get("keystoreType");
  	    if( keystoreType==null) keystoreType=defaultKeystoreType;
  
  	    //determine whether we want client authentication
  	    // the presence of the attribute enables client auth
  	    clientAuth = null != (String)attributes.get("clientauth");
  
  	    String keyPass=(String)attributes.get("keypass");
  	    if( keyPass==null) keyPass=defaultKeyPass;
  
  	    //protocol for the SSL ie - TLS, SSL v3 etc.
  	    String protocol = (String)attributes.get("protocol");
  	    if(protocol == null) protocol = defaultProtocol;
  	    
  	    //Algorithm used to encode the certificate ie - SunX509
  	    String algorithm = (String)attributes.get("algorithm");
  	    if(algorithm == null) algorithm = defaultAlgorithm;
  	    
  	    // You can't use ssl without a server certificate.
  	    // Create a KeyStore ( to get server certs )
  	    KeyStore kstore = initKeyStore( keystoreFile, keyPass );
  	    
  	    // Create a SSLContext ( to create the ssl factory )
  	    // This is the only way to use server sockets with JSSE 1.0.1
  	    com.sun.net.ssl.SSLContext context = 
  		com.sun.net.ssl.SSLContext.getInstance(protocol); //SSL
  
  	    // Key manager will extract the server key
  	    com.sun.net.ssl.KeyManagerFactory kmf = 
  		com.sun.net.ssl.KeyManagerFactory.getInstance(algorithm);
  	    kmf.init( kstore, keyPass.toCharArray());
  
  	    // XXX I don't know if this is needed
  //  	    com.sun.net.ssl.TrustManagerFactory tmf = 
  //  		com.sun.net.ssl.TrustManagerFactory.getInstance("SunX509");
  // 		tmf.init(kstore);
  
  	    // init context with the key managers
  	    context.init(kmf.getKeyManagers(), null,
  			 new java.security.SecureRandom());
  
  	    // create proxy
  	    sslProxy = context.getServerSocketFactory();
  
  	    return;
  	} catch(Exception e) {
  	    if( e instanceof IOException )
  		throw (IOException)e;
  	    throw new IOException(e.getMessage());
  	}
      }
  
      /** Set server socket properties ( accepted cipher suites, etc)
       */
      private void initServerSocket(ServerSocket ssocket) {
  	SSLServerSocket socket=(SSLServerSocket)ssocket;
  
  	// We enable all cipher suites when the socket is
  	// connected - XXX make this configurable 
  	String cipherSuites[] = socket.getSupportedCipherSuites();
  	socket.setEnabledCipherSuites(cipherSuites);
  
  	// we don't know if client auth is needed -
  	// after parsing the request we may re-handshake
  	socket.setNeedClientAuth(clientAuth);
      }
  
      private KeyStore initKeyStore( String keystoreFile,
  				   String keyPass)
  	throws IOException
      {
  	InputStream istream = null;
  	try {
  	    KeyStore kstore=KeyStore.getInstance( keystoreType );
  	    istream = new FileInputStream(keystoreFile);
  	    kstore.load(istream, keyPass.toCharArray());
  	    return kstore;
  	}
  	catch (FileNotFoundException fnfe) {
  	    throw fnfe;
  	}
  	catch (IOException ioe) {
  	    throw ioe;	    
  	}
  	catch(Exception ex) {
  	    ex.printStackTrace();
  	    throw new IOException( "Exception trying to load keystore " +
  				   keystoreFile + ": " + ex.getMessage() );
  	}
      }
  
      
  }
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/net/ServerSocketFactory.java
  
  Index: ServerSocketFactory.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.tomcat.util.net;
  
  import java.io.*;
  import java.net.*;
  import java.util.Hashtable;
  
  /**
   * This class creates server sockets.  It may be subclassed by other
   * factories, which create particular types of server sockets.  This
   * provides a general framework for the addition of public socket-level
   * functionality.  It it is the server side analogue of a socket factory,
   * and similarly provides a way to capture a variety of policies related
   * to the sockets being constructed.
   *
   * <P> Like socket factories, Server Socket factory instances have two
   * categories of methods.  First are methods used to create sockets.
   * Second are methods which set properties used in the production of
   * sockets, such as networking options.  There is also an environment
   * specific default server socket factory; frameworks will often use
   * their own customized factory.
   * 
   * <P><hr><em> It may be desirable to move this interface into the
   * <b>java.net</b> package, so that is not an extension but the preferred
   * interface.  Should this be serializable, making it a JavaBean which can
   * be saved along with its networking configuration?
   * </em>   
   *
   * @author db@eng.sun.com
   * @author Harish Prabandham
   */
  public abstract class ServerSocketFactory implements Cloneable {
  
      //
      // NOTE:  JDK 1.1 bug in class GC, this can get collected
      // even though it's always accessible via getDefault().
      //
  
      private static ServerSocketFactory theFactory;
      protected Hashtable attributes=new Hashtable();
  
      /**
       * Constructor is used only by subclasses.
       */
  
      protected ServerSocketFactory () {
          /* NOTHING */
      }
  
      /** General mechanism to pass attributes from the
       *  ServerConnector to the socket factory.
       *
       *  Note that the "prefered" mechanism is to
       *  use bean setters and explicit methods, but
       *  this allows easy configuration via server.xml
       *  or simple Properties
       */
      public void setAttribute( String name, Object value ) {
  	if( name!=null && value !=null)
  	    attributes.put( name, value );
      }
      
      /**
       * Returns a copy of the environment's default socket factory.
       */
      public static ServerSocketFactory getDefault () {
          //
          // optimize typical case:  no synch needed
          //
  
          if (theFactory == null) {
              synchronized (ServerSocketFactory.class) {
                  //
                  // Different implementations of this method could
                  // work rather differently.  For example, driving
                  // this from a system property, or using a different
                  // implementation than JavaSoft's.
                  //
  
                  theFactory = new DefaultServerSocketFactory ();
              }
          }
  
          try {
              return (ServerSocketFactory) theFactory.clone ();
          } catch (CloneNotSupportedException e) {
              throw new RuntimeException (e.getMessage ());
          }
      }
  
      /**
       * Returns a server socket which uses all network interfaces on
       * the host, and is bound to a the specified port.  The socket is
       * configured with the socket options (such as accept timeout)
       * given to this factory.
       *
       * @param port the port to listen to
       * @exception IOException for networking errors
       * @exception InstantiationException for construction errors
       */
      public abstract ServerSocket createSocket (int port)
      throws IOException, InstantiationException;
  
      /**
       * Returns a server socket which uses all network interfaces on
       * the host, is bound to a the specified port, and uses the 
       * specified connection backlog.  The socket is configured with
       * the socket options (such as accept timeout) given to this factory.
       *
       * @param port the port to listen to
       * @param backlog how many connections are queued
       * @exception IOException for networking errors
       * @exception InstantiationException for construction errors
       */
  
      public abstract ServerSocket createSocket (int port, int backlog)
      throws IOException, InstantiationException;
  
      /**
       * Returns a server socket which uses only the specified network
       * interface on the local host, is bound to a the specified port,
       * and uses the specified connection backlog.  The socket is configured
       * with the socket options (such as accept timeout) given to this factory.
       *
       * @param port the port to listen to
       * @param backlog how many connections are queued
       * @param ifAddress the network interface address to use
       * @exception IOException for networking errors
       * @exception InstantiationException for construction errors
       */
  
      public abstract ServerSocket createSocket (int port,
          int backlog, InetAddress ifAddress)
      throws IOException, InstantiationException;
  
      public void initSocket( Socket s ) {
      }
  }
  
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/net/TcpConnection.java
  
  Index: TcpConnection.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/net/TcpConnection.java,v 1.1 2000/08/14 21:54:37 costin Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/14 21:54:37 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.tomcat.util.net;
  
  import org.apache.tomcat.util.*;
  import java.io.*;
  import java.net.*;
  import java.util.*;
  
  /**
   *
   */
  public class TcpConnection  { // implements Endpoint {
  
      public TcpConnection() {
      }
  
      // -------------------- Properties --------------------
  
      PoolTcpEndpoint endpoint;
      Socket socket;
  
      public void setEndpoint(PoolTcpEndpoint endpoint) {
  	this.endpoint = endpoint;
      }
  
      public PoolTcpEndpoint getEndpoint() {
  	return endpoint;
      }
  
      public void setSocket(Socket socket) {
  	this.socket=socket;
      }
  
      public Socket getSocket() {
  	return socket;
      }
  
      public void recycle() {
          endpoint = null;
          socket = null;
      }
  }
  
  
  
  
  
  1.1                  jakarta-tomcat/src/share/org/apache/tomcat/util/net/TcpConnectionHandler.java
  
  Index: TcpConnectionHandler.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/net/TcpConnectionHandler.java,v 1.1 2000/08/14 21:54:37 costin Exp $
   * $Revision: 1.1 $
   * $Date: 2000/08/14 21:54:37 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */ 
  
  package org.apache.tomcat.util.net;
  
  import java.io.*;
  import java.net.*;
  import java.util.*;
  import org.apache.tomcat.util.*;
  
  /**
   * 
   */
  public interface TcpConnectionHandler {
      /** Add informations about the a "controler" object
       *  specific to the server. In tomcat it will be a
       *  ContextManager.
       */
      public void setServer(Object manager);
  
      
      /** Used to pass config informations to the handler
       */
      public void setAttribute(String name, Object value );
      
      /** Called before the call to processConnection.
       *  If the thread is reused, init() should be called once per thread.
       *
       *  It may look strange, but it's a _very_ good way to avoid synchronized
       *  methods and keep per thread data.
       *  You are not required to implement it, but if you do - you can save a lot
       *  in allocation ( since this will be called outside critical path ).
       */
      public Object[] init( );
  
      /**
       *  Assert: connection!=null
       *  Assert: connection.getSocket() != null
       *  Assert: thData != null, result of calling init()
       */
      public void processConnection(TcpConnection connection, Object thData[]);    
  }
  
  
  

Mime
View raw message