xml-rpc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject cvs commit: xml-rpc/src/java/org/apache/xmlrpc WebServer.java
Date Sat, 11 Aug 2001 10:13:07 GMT
dlr         01/08/11 03:13:07

  Modified:    src/java/org/apache/xmlrpc WebServer.java
  Log:
  * Added createServerSocket() factory method (for subclassing by
  SecureWebServer).
  
  * Refactored setupServerSocket() method to initialize the WebServer's
  listener to the socket created by createServerSocket().  Also set a
  timeout on the socket so it doesn't block forever when accept() is
  called (more on this below).
  
  * Since SO_TIMEOUT is now being set on our listener socket, we can
  actually shutdown properly now.  An InterruptedIOException will be
  thrown every 4 seconds while the listener is blocking on accept().  If
  the server has been told to shutdown, this will allow it to actually
  happen before another client connection comes in.  This bug was
  originally reported by Ilkka Priha <ipriha@surfeu.fi>, and was fixed
  by myself long ago (while it was still @ Helma):
  
  "The helma webserver shutdown method sets a listener acting as a flag
  to null and calls interrupt() for the thread, but blocking I/O
  operations don't care about thread interrupts. By default, the server
  socket accept() method waits forever or until the socket is closed. I
  think that the server socket should either have a preset SO_TIMEOUT
  interrupting I/O waits at regular intervals or the shutdown() method
  should simply close the server socket."
  
  * Formatting cleanup.
  
  Revision  Changes    Path
  1.3       +34 -6     xml-rpc/src/java/org/apache/xmlrpc/WebServer.java
  
  Index: WebServer.java
  ===================================================================
  RCS file: /home/cvs/xml-rpc/src/java/org/apache/xmlrpc/WebServer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -u -r1.2 -r1.3
  --- WebServer.java	2001/08/06 01:36:53	1.2
  +++ WebServer.java	2001/08/11 10:13:07	1.3
  @@ -64,6 +64,7 @@
    *
    * @author <a href="mailto:hannes@apache.org">Hannes Wallnoefer</a>
    * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  + * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
    */
   public class WebServer 
       implements Runnable
  @@ -162,10 +163,31 @@
           start();
       }
   
  -    public void setupServerSocket(int port, int x, InetAddress add) 
  +    /**
  +     * Factory method to manufacture the server socket.  Useful as a
  +     * hook method for subclasses to override when they desire
  +     * different flavor of socket (i.e. a <code>SSLServerSocket</code>).
  +     *
  +     * @exception Exception Error creating listener socket.
  +     */
  +    protected ServerSocket createServerSocket(int port, int backlog, InetAddress add)
  +        throws Exception
  +    {
  +        return new ServerSocket(port, backlog, add);
  +    }
  +
  +    /**
  +     * Initializes this server's listener socket with the specified
  +     * attributes.  The <code>createServerSocket()</code> method can
  +     * be overridden to change the flavor of socket used.
  +     *
  +     * @see #createServerSocket(int port, int backlog, InetAddress add)
  +     */
  +    public void setupServerSocket(int port, int backlog, InetAddress add)
           throws Exception
       {
  -        this.serverSocket = new ServerSocket (port, x, add);
  +        serverSocket = createServerSocket(port, backlog, add);
  +        serverSocket.setSoTimeout(4096);
       }
   
       public void start()
  @@ -285,6 +307,11 @@
                       else
                           socket.close ();
                   }
  +                catch (InterruptedIOException checkState)
  +                {
  +                    // Timeout while waiting for a client (from
  +                    // SO_TIMEOUT)...try again if still listening.
  +                }
                   catch (Exception ex)
                   {
                       System.err.println(
  @@ -304,7 +331,9 @@
               System.err.println( "Error accepting XML-RPC connections (" +
                       exception + ").");
           }
  -        finally { System.err.println("Closing XML-RPC server socket.");
  +        finally
  +        {
  +            System.err.println("Closing XML-RPC server socket.");
               try
               {
                   serverSocket.close();
  @@ -312,8 +341,8 @@
               }
               catch (IOException ignore)
                   {}
  -        } }
  -
  +        }
  +    }
   
       /**
         * Stop listening on the server port.
  @@ -599,4 +628,3 @@
           }
       }
   }
  -
  
  
  

Mime
View raw message