Tidy receive_stream

This commit is contained in:
Brian Candler
2011-05-01 18:17:03 +01:00
parent 63fd7d18b6
commit 14f8a27d2b

View File

@@ -153,10 +153,11 @@ module Netlink
end end
# Loop infinitely receiving messages of given type(s), ignoring pid and seq. # Loop infinitely receiving messages of given type(s), ignoring pid and seq.
def receive_stream(*expected_type) # Raises an exception on NLMSG_ERROR.
def receive_stream(*expected_types)
loop do loop do
receive_response(nil) do |type, flags, seq, pid, msg| receive_response(nil) do |type, flags, seq, pid, msg|
if expected_type.include?(type) if expected_types.include?(type)
yield msg yield msg
elsif type == NLMSG_ERROR elsif type == NLMSG_ERROR
raise ERRNO_MAP[-msg.error] || "Netlink Error: #{msg.inspect}" raise ERRNO_MAP[-msg.error] || "Netlink Error: #{msg.inspect}"