1   /*
2    * Copyright (C) The Spice Group. All rights reserved.
3    *
4    * This software is published under the terms of the Spice
5    * Software License version 1.1, a copy of which has been included
6    * with this distribution in the LICENSE.txt file.
7    */
8   package org.codehaus.spice.netserve.connection.impl;
9   
10  import java.io.IOException;
11  import java.net.ServerSocket;
12  import java.net.Socket;
13  
14  /***
15   *
16   * @author Peter Donald
17   * @version $Revision: 1.2 $ $Date: 2004/03/21 23:42:59 $
18   */
19  class BlockingServerSocket
20     extends ServerSocket
21  {
22     static final Socket SOCKET = new Socket();
23  
24     private int m_lockCount;
25     private int m_acceptCount;
26  
27     public BlockingServerSocket()
28        throws IOException
29     {
30     }
31  
32     public Socket accept()
33        throws IOException
34     {
35        m_acceptCount++;
36        while ( true )
37        {
38           synchronized ( this )
39           {
40              if ( m_acceptCount <= m_lockCount )
41              {
42                 break;
43              }
44              try
45              {
46                 wait( 100 );
47              }
48              catch ( InterruptedException e )
49              {
50              }
51              notifyAll();
52           }
53        }
54        return SOCKET;
55     }
56  
57     synchronized void unlock()
58     {
59        m_lockCount++;
60        notifyAll();
61     }
62  }