tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brad Cox PhD <b...@virtualschool.edu>
Subject RE: ServerSocket not being closed properly.
Date Tue, 24 Apr 2001 13:42:14 GMT
At 7:19 PM -0700 04/23/2001, cmanolache@yahoo.com wrote:
>On Mon, 23 Apr 2001, Arun Katkere wrote:
>In general you need to do something to unblock the accept thread, and 3.2
>doesn't have this in.

Yes, I remember now. You're absolutely right. You need 
serverSocket.setSoTimeout() to break the accept periodically. Here's 
how I did it in my app.

Notice the comment: apparently I got this from an early version of Tomcat.

  public void run()
  {
   if (serverSocket != null) // original is server
   {
    isListening = true;
    while(isListening)
    {
     try
     {
      Socket clientSocket = serverSocket.accept();
      SocketServer clone = (SocketServer)clone();
      clone.serverSocket = null;
      clone.clientSocket = clientSocket;
      clone.thread = new Thread(clone, name+"Clone");
      clone.thread.start();
     }
     catch (InterruptedIOException e)
     {
      /**
       * Ignore periodic SO_TIMEOUT interrupts
       * Without this the accept call never returns when the serversocket
       * is closed, and all subsequent runs fail with "port 8082 busy".
       * I found this in the  Tomcat http server code.
       */
     }
     catch (Throwable e)
     { e.printStackTrace(); isListening = false; }
    }
   }
   else run(clientSocket);
  }
  void startServer(int port) throws UserFault
  {
   if (thread == null)
   {
    try
    {
     serverSocket = new ServerSocket(port);
     serverSocket.setSoTimeout(WAKEUP_INTERVAL);
    }
    catch (IOException e)
    {
     throw UserFault.errEnablerPortBusy(port);
    }
    thread = new Thread(this, name+"Master");
    isListening = true;
    thread.start();
   }
  }
-- 
---
Brad Cox, Ph.D.; bcox@virtualschool.edu
Phone: 703 361 4751 Cell: 703 919-9623
http://virtualschool.edu

Mime
View raw message