lib/rmpd/command.rb in rmpd-1.1.9 vs lib/rmpd/command.rb in rmpd-1.1.11

- old
+ new

@@ -21,10 +21,14 @@ def self.choose_strategy(name) if /command_list_ok/ === name CommandListOkStrategy elsif /command_list/ === name CommandListStrategy + elsif /^noidle$/ === name + NoidleStrategy + elsif /^idle$/ === name + IdleStrategy else CommandStrategy end end @@ -32,16 +36,49 @@ list = List.new yield list list end + module IdleStrategy + + def execute(connection, *args, &block) + connection.send_command(@name, *args) + if block_given? + yield connection.socket rescue nil + connection.send_command("noidle") + end + Response.factory(@name).parse(connection.read_response) + rescue EOFError + puts "IdleStrategy EOFError received, retrying" if $DEBUG + connection.close + retry + end + + end + + module NoidleStrategy + + def execute(connection, *args) + connection.send_command(@name, *args) + # The MPD server will never respond to a noidle command. + # http://www.mail-archive.com/musicpd-dev-team@lists.sourceforge.net/msg02246.html + nil + rescue EOFError + puts "NoidleStrategy EOFError received, retrying" if $DEBUG + connection.close + retry + end + + end + module CommandStrategy def execute(connection, *args) connection.send_command(@name, *args) Response.factory(@name).parse(connection.read_response) rescue EOFError + puts "CommandStrategy EOFError received, retrying" if $DEBUG connection.close retry end end @@ -56,10 +93,14 @@ list.map do |command_w_args| connection.send_command(*command_w_args) end connection.send_command("command_list_end") Response.factory(@name).parse(connection.read_response) + rescue EOFError + puts "CommandListStrategy EOFError received, retrying" if $DEBUG + connection.close + retry end end module CommandListOkStrategy @@ -72,9 +113,13 @@ @list.map do |command_w_args| connection.send_command(*command_w_args) end connection.send_command("command_list_end") handle_command_list_ok_response(connection.read_response) + rescue EOFError + puts "CommandListOkStrategy EOFError received, retrying" if $DEBUG + connection.close + retry end private