Return-Path: Mailing-List: contact rpc-dev-help@xml.apache.org; run by ezmlm Delivered-To: mailing list rpc-dev@xml.apache.org Delivered-To: moderator for rpc-dev@xml.apache.org Received: (qmail 13071 invoked by uid 500); 11 Aug 2001 10:15:35 -0000 Delivered-To: apmail-xml-rpc-cvs@apache.org Received: (qmail 13064 invoked from network); 11 Aug 2001 10:15:35 -0000 Received: from h32.sny.collab.net (HELO icarus.apache.org) (64.208.42.42) by h31.sny.collab.net with SMTP; 11 Aug 2001 10:15:35 -0000 Received: (qmail 53196 invoked by uid 1164); 11 Aug 2001 10:13:07 -0000 Date: 11 Aug 2001 10:13:07 -0000 Message-ID: <20010811101307.53195.qmail@icarus.apache.org> From: dlr@apache.org To: xml-rpc-cvs@apache.org Subject: cvs commit: xml-rpc/src/java/org/apache/xmlrpc WebServer.java X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N 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 , 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 Hannes Wallnoefer * @author Jason van Zyl + * @author Daniel Rall */ 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 SSLServerSocket). + * + * @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 createServerSocket() 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 @@ } } } -