about summary refs log tree commit homepage
path: root/lib/raindrops/linux.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-04-08 14:26:04 -0700
committerEric Wong <normalperson@yhbt.net>2010-04-08 14:26:04 -0700
commitda0d9cbbd9f6cf2e68274dd5c2204b105f8b030d (patch)
tree6ceefa22e616534019d6061e5b2b2e0de9fdfa1d /lib/raindrops/linux.rb
parentb9eeebe9d448431a97ac4515cae6a53b6976ac4e (diff)
downloadraindrops-da0d9cbbd9f6cf2e68274dd5c2204b105f8b030d.tar.gz
File.read under 1.9 takes an :encoding argument to force binary
encoding for its return value.
Diffstat (limited to 'lib/raindrops/linux.rb')
-rw-r--r--lib/raindrops/linux.rb15
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/raindrops/linux.rb b/lib/raindrops/linux.rb
index 6dff73f..ba2d975 100644
--- a/lib/raindrops/linux.rb
+++ b/lib/raindrops/linux.rb
@@ -5,7 +5,8 @@ module Linux
   # The standard proc path for active UNIX domain sockets, feel free to call
   # String#replace on this if your /proc is mounted in a non-standard location
   # for whatever reason
-  PROC_NET_UNIX = "/proc/net/unix"
+  PROC_NET_UNIX_ARGS = %w(/proc/net/unix)
+  defined?(::Encoding) and PROC_NET_UNIX_ARGS.push({ :encoding => "binary" })
 
   # Get ListenStats from an array of +paths+
   #
@@ -36,13 +37,11 @@ module Linux
     paths = / 00000000 \d+ (\d+)\s+\d+ (#{paths.join('|')})$/n
 
     # no point in pread since we can't stat for size on this file
-    File.open(PROC_NET_UNIX, "rb") do |fp|
-      fp.read.scan(paths).each do |s|
-        path = s.last
-        case s.first.to_i
-        when 2 then rv[path].queued += 1
-        when 3 then rv[path].active += 1
-        end
+    File.read(*PROC_NET_UNIX_ARGS).scan(paths) do |s|
+      path = s.last
+      case s.first.to_i
+      when 2 then rv[path].queued += 1
+      when 3 then rv[path].active += 1
       end
     end