about summary refs log tree commit homepage
path: root/examples
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-03-08 16:30:47 -0800
committerEric Wong <normalperson@yhbt.net>2011-03-08 16:30:47 -0800
commit93bb8af761dbaa8e19c4660c520db1ee7ba1c70b (patch)
tree68b35c5027bd4050fbd5c05aacc166c2dd4c2c41 /examples
parent90726e5187a9053c6eb7caf90ebec1d38d4372ea (diff)
downloadraindrops-93bb8af761dbaa8e19c4660c520db1ee7ba1c70b.tar.gz
No need to make eyes drift :)
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/linux-listener-stats.rb14
1 files changed, 11 insertions, 3 deletions
diff --git a/examples/linux-listener-stats.rb b/examples/linux-listener-stats.rb
index d675ee1..cb48ef7 100755
--- a/examples/linux-listener-stats.rb
+++ b/examples/linux-listener-stats.rb
@@ -1,4 +1,5 @@
 #!/usr/bin/ruby
+# -*- encoding: binary -*-
 $stdout.sync = $stderr.sync = true
 # this is used to show or watch the number of active and queued
 # connections on any listener socket from the command line
@@ -38,15 +39,22 @@ ARGV.each do |addr|
   end
 end
 
+len = "address".size
 now = nil
-fmt = "%20s % 35s % 10u % 10u\n"
-$stderr.printf fmt.tr('u','s'), *%w(timestamp address active queued)
 tcp, unix = [], []
-ARGV.each { |addr| (addr =~ %r{\A/} ? unix : tcp) << addr }
+ARGV.each do |addr|
+  bs = addr.respond_to?(:bytesize) ? addr.bytesize : addr.size
+  len = bs if bs > len
+  (addr =~ %r{\A/} ? unix : tcp) << addr
+end
 combined = {}
 tcp = nil if tcp.empty?
 unix = nil if unix.empty?
 
+len = 35 if len > 35
+fmt = "%20s % #{len}s % 10u % 10u\n"
+$stderr.printf fmt.tr('u','s'), *%w(timestamp address active queued)
+
 begin
   if now
     combined.clear