diff -ru webrick/lib/webrick/server.rb webric
k-t2/lib/webrick/server.rb
--- webrick/lib/w
ebrick/server.rb	Wed Mar 20 17:51:24 2002
++
+ webrick-t2/lib/webrick/server.rb	Thu Mar 28
 23:43:16 2002
@@ -81,42 +81,52 @@
 
     
  server_type.start{
         thgroup = Arra
y.new
-        queue   = SizedQueue.new(star
t_threads)
+        queue   = Queue.new
 
         @logger.info "#{self.type}#start: pi
d=#{$$} port=#{@config[:Port]}"
         sta
rt_hook()
+	
+	done_threads = Queue.new
 
-        start_threads.times{ |i|
-        
  th = Thread.start(i){ |j|
-            @lo
gger.info "thread(#{j}) start."
-           
 loop do
-              sock = queue.pop
- 
             case sock
-              when I
PSocket
-                begin
-           
       Thread.current[:WEBrickSocket] = sock
-                  addr = sock.peeraddr
-  
                @logger.debug "accept: #{addr
[3]}:#{addr[1]}"
-                  accept_h
ook(sock)
-                  block_given? ? 
yield(sock) : run(sock)
-                res
cue Errno::ENOTCONN => ex
-                 
 msg = "#{ex.type}: #{ex.message}\n\t#{ex.bac
ktrace[0]}"
-                  @logger.error
 msg
-                rescue Exception => ex
-                  @logger.error ex
-     
           ensure
-                  Thread.
current[:WEBrickSocket] = nil
-             
     @logger.debug "close: #{addr[3]}:#{addr[
1]}"
-                  sock.close
-       
         end
-              else
-         
       @logger.info "thread(#{j}) exit."
-  
              Thread.exit
-              end
-            end
-          }
-          
thgroup.push(th)
-        }
+	start_thread 
= Proc.new { |num,sock|
+	  Thread.start {
+	    @logger.info "thread(#{num}) start."
+
	    loop do
+	      begin
+		timeout(10.0)
 {
+		  sock ||= queue.pop
+		}
+	      re
scue TimeoutError
+	      end
+	      case 
sock
+	      when IPSocket
+		begin
+		  T
hread.current[:WEBrickSocket] = sock
+		  ad
dr = sock.peeraddr
+		  @logger.debug "accep
t: #{addr[3]}:#{addr[1]}"
+		  accept_hook(s
ock)
+		  block_given? ? yield(sock) : run(s
ock)
+		rescue Errno::ENOTCONN => ex
+		  m
sg = "#{ex.type}: #{ex.message}\n\t#{ex.backt
race[0]}"
+		  @logger.error msg
+		rescue 
Exception => ex
+		  @logger.error ex
+		en
sure
+		  Thread.current[:WEBrickSocket] = n
il
+		  @logger.debug "close: #{addr[3]}:#{a
ddr[1]}"
+		  sock.close
+		end
+	      el
se
+		@logger.info "thread(#{num}) exit."
+
		done_threads.push Thread.current
+		Thread
.exit
+	      end
+	      sock = nil
+	   
 end
+	  }
+	}
+
+	threadnum = 0
 
    
     @status = :Running
         while @stat
us == :Running
@@ -126,9 +136,19 @@
       
          socks[0].each{|s|
                
   ns = s.accept
                   ns.sync 
= true
-                  queue.push(ns)
+	
	  if queue.num_waiting == 0
+		    thgroup.
push start_thread.call(threadnum+=1,ns)
+		 
 else
+		    queue.push(ns)
+		  end
     
            }
               end
+	      be
gin
+		while th = done_threads.pop(true)
+	
	  thgroup.delete th
+		end
+	      rescue 
ThreadError
+	      end
             }
   
        rescue TimeoutError => ex
          
 rescue Errno::ECONNRESET, Errno::ECONNABORTE
D,