Permalink
Browse files

utils/stress: some other fixes

  • Loading branch information...
1 parent 5c0546c commit fa912898fc9ccf3be5833a6d0fa256b46ce31c5f @meh committed Jul 16, 2011
Showing with 30 additions and 27 deletions.
  1. +30 −27 utils/stress.rb
View
@@ -67,7 +67,9 @@ def number= (value)
if value < number
tmp, @number = number, value
- slice!(tmp - value, length)
+ slice!(tmp - value, length).each {|socket|
+ socket.close
+ }
else
@number = value
end
@@ -115,41 +117,41 @@ def spawn
Thread.new {
loop do
- begin
- Thread.new {
- @sockets.spawn
- }
+ Thread.new {
+ @sockets.spawn
+ }
- begin
- reading, = IO.select(@sockets)
- rescue; next; end
+ begin
+ reading, = IO.select(@sockets)
+ rescue; next; end
- reading.each {|socket|
- if socket.class == IO
- socket.read_nonblock 2048
- next
- end
+ reading.each {|socket|
+ if socket.class == IO
+ socket.read_nonblock 2048
+ next
+ end
- line = socket.gets or socket.close and next
+ line = socket.gets or socket.close && next
- COMMANDS.each {|regex, block|
- if matches = regex.match(line)
+ COMMANDS.each {|regex, block|
+ if matches = regex.match(line)
+ begin
socket.instance_exec matches, &block
+ rescue Exception => e
+ IRC.debug e
end
- }
+ end
}
+ }
- unless @input.empty?
- line = @input.pop
+ unless @input.empty?
+ line = @input.pop
- @sockets.each {|socket|
- next if socket.class == IO
+ @sockets.each {|socket|
+ next if socket.class == IO
- socket.write_nonblock line
- }
- end
- rescue Exception => e
- IRC.debug e
+ socket.write_nonblock line
+ }
end
end
}
@@ -160,8 +162,9 @@ def spawn
@input.push eval("%{#{$1}}")
@sockets.wakeup
- when /^clients\s+(.*?)/
+ when /^clients\s+(.*)$/
@sockets.number = $1.to_i
+ @sockets.wakeup
end
end

0 comments on commit fa91289

Please sign in to comment.