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 = Array.new
- queue = SizedQueue.new(star
t_threads)
+ queue = Queue.new
@logger.info "#{self.type}#start: pid=#{$$} port=#{@config[:Port]}"
start_hook()
+
+ done_threads = Queue.new
- start_threads.times{ |i|
- th = Thread.start(i){ |j|
- @logger.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_hook(sock)
- block_given? ?
yield(sock) : run(sock)
- res
cue Errno::ENOTCONN => ex
-
msg = "#{ex.type}: #{ex.message}\n\t#{ex.backtrace[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
+ }
+ rescue 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(sock)
+ block_given? ? yield(sock) : run(s
ock)
+ rescue Errno::ENOTCONN => ex
+ m
sg = "#{ex.type}: #{ex.message}\n\t#{ex.backtrace[0]}"
+ @logger.error msg
+ rescue
Exception => ex
+ @logger.error ex
+ en
sure
+ Thread.current[:WEBrickSocket] = n
il
+ @logger.debug "close: #{addr[3]}:#{addr[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 @status == :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
+ begin
+ while th = done_threads.pop(true)
+
thgroup.delete th
+ end
+ rescue
ThreadError
+ end
}
rescue TimeoutError => ex
rescue Errno::ECONNRESET, Errno::ECONNABORTE
D,