You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@apache.org on 2002/01/12 05:00:15 UTC

cvs commit: jakarta-tomcat-connectors/jk/java/org/apache/jk/apr AprInputStream.java AprOutputStream.java AprSocketServer.java

costin      02/01/11 20:00:15

  Added:       jk/java/org/apache/jk/apr AprInputStream.java
                        AprOutputStream.java AprSocketServer.java
  Log:
  Abstractions for the apr is, os, socket. Initial version based on JFC's
  unix socket ( which will eventually be part of the standard apr ).
  
  Those are very early, and jk is using the AprImpl directly. In time
  we should make them implement completely the java interfaces ( for
  example use Socket, etc ).
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-connectors/jk/java/org/apache/jk/apr/AprInputStream.java
  
  Index: AprInputStream.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.jk.apr;
  
  import java.io.*;
  
  import java.net.*;
  import java.util.*;
  
  import org.apache.tomcat.util.buf.*;
  import org.apache.tomcat.util.http.*;
  
  import org.apache.tomcat.util.threads.*;
  
  /**
   * Provide an InputStream for the native socket.
   * 
   *
   * @author Jean-Frederic Clere
   * @author Costin Manolache
   */
  class AprInputStream extends InputStream {
      int type; // right now only LOCAL
      private int fd; // From openNative.
      private AprImpl apr;
      long pool;
  
      /**
       * Create an InputStream using apr for I/O. This can
       * support multiple 'styles' ( unix socket, apr tcp socket,
       * etc ). We could split it - the interfaces are highly
       * experimental for now.
       */ 
      public AprInputStream(AprImpl apr, long pool, int type, int fd) {
          this.apr=apr;
          this.fd = fd;
          this.pool=pool;
          this.type=type;
      }
  
      public int read() throws IOException {
          byte buf [] = new byte[1];
          if ( apr.unRead( pool, fd, buf, 0, 1) < 0)
              throw new IOException();
          return 0xff & buf[0];
      }
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/jk/java/org/apache/jk/apr/AprOutputStream.java
  
  Index: AprOutputStream.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.jk.apr;
  
  import java.io.*;
  
  import java.net.*;
  import java.util.*;
  
  import org.apache.tomcat.util.buf.*;
  import org.apache.tomcat.util.http.*;
  
  import org.apache.tomcat.util.threads.*;
  
  
  /**
   * Provide an OutputStream for the native socket.
   *
   *
   * @author Jean-Frederic Clere
   * @author Costin Manolache
   */
  class AprOutputStream extends OutputStream {
      int type; // right now only LOCAL
      private int fd; // From openNative.
      private AprImpl apr;
      long pool;
  
      /**
       * Create an OutputStream using apr for I/O. This can
       * support multiple 'styles' ( unix socket, apr tcp socket,
       * etc ). We could split it - the interfaces are highly
       * experimental for now.
       */ 
      public AprOutputStream(AprImpl apr, long pool, int type, int fd) {
          this.apr=apr;
          this.fd = fd;
          this.pool=pool;
          this.type=type;
      }
  
      public void write(int value) throws IOException {
          byte buf [] = new byte[] { (byte) value };
          // based on type select the native write method
          // Or separate classes for each type - but we expect UNIX
          // sockets to be integrated in apr
          if ( apr.unWrite( pool, fd, buf, 0, 1 ) < 0)
              throw new IOException();
      }
  
      public void write(byte b[], int off, int len) throws IOException {
          if ( apr.unWrite( pool, fd, b, off, len ) < 0)
              throw new IOException();
      }
  
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/jk/java/org/apache/jk/apr/AprSocketServer.java
  
  Index: AprSocketServer.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.jk.apr;
  
  import java.io.*;
  
  import java.net.*;
  import java.util.*;
  
  import org.apache.tomcat.util.buf.*;
  import org.apache.tomcat.util.http.*;
  
  import org.apache.tomcat.util.threads.*;
  
  
  /**
   * Native AF_UNIX socket server
   */
  class AprSocketServer {
      private int fd; // From socket + bind.
  
      private static native int createSocketNative (String filename);
  
      private static native int acceptNative (int fd);
      private static native int closeNative (int fd);
      private static native int setSoTimeoutNative (int fd,int value);
  
      public AprSocketServer() throws IOException {
          fd = createSocketNative("/usr/tmp/apache_socket");
          if (fd<0) 
              throw new IOException();	
      }
      
      public AprSocket accept() throws IOException {
          AprSocket socket = new AprSocket();
          socket.fd = acceptNative(this.fd);
          if (socket.fd<0)
              throw new IOException();
          return socket;
      }
      
      public void setSoTimeout(int value) throws SocketException {
          if (setSoTimeoutNative(this.fd, value)<0)
              throw new SocketException();
      }
      
      public void close() {
          closeNative(this.fd);
      }
  }
  
  /**
   * Native AF_UNIX socket
   */
  class AprSocket {
      public int fd; // From accept.
  
      private static native int setSoLingerNative (int fd, int l_onoff,
                                                   int l_linger);
  
      public void setSoLinger  (boolean bool ,int l_linger) throws IOException {
          int l_onoff=0;
          if (bool)
              l_onoff = 1;
          if (setSoLingerNative(fd,l_onoff,l_linger)<0)
  
              throw new IOException();
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>