From da0d9cbbd9f6cf2e68274dd5c2204b105f8b030d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 8 Apr 2010 14:26:04 -0700 Subject: [PATCH] linux: slightly simpler scan for /proc/net/unix File.read under 1.9 takes an :encoding argument to force binary encoding for its return value. --- lib/raindrops/linux.rb | 15 +++++++-------- 1 file 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 -- 2.11.4.GIT