Simple address/link/route memoization

This commit is contained in:
Brian Candler
2011-04-29 18:28:37 +01:00
parent 8c8d199a09
commit cf255395e1
2 changed files with 108 additions and 49 deletions

View File

@@ -109,9 +109,9 @@ module Netlink
# are accepted.
#
# (Compare: rtnl_dump_filter_l in lib/libnetlink.c)
def receive_until_done(expect_type=nil, timeout=@timeout, junk_handler=nil, &blk) #:yields: type, flags, obj
def receive_until_done(expect_type=nil, timeout=@timeout, junk_handler=nil, &blk) #:yields: obj
res = []
blk ||= lambda { |type, flags, obj| res << obj if obj }
blk ||= lambda { |obj| res << obj }
junk_handler ||= lambda { |type, flags, seq, pid, obj|
warn "Discarding junk message (#{type}) #{obj}" } if $VERBOSE
loop do
@@ -130,7 +130,7 @@ module Netlink
junk_handler[type, flags, seq, pid, obj] if junk_handler
next
end
blk.call(type, flags, obj)
blk.call(obj) if obj
end
end
end