[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Don't lock on custom server connection failures

Mike Massonnet noreply at xfce.org
Sat Jan 30 15:12:03 CET 2010


Updating branch refs/heads/aria2-xml-rpc
         to ac73d2895a4e0ee8d57486b5c0fe06ca2f108bca (commit)
       from 4f5695d31b402ba00bbf7c6d263bce84050b6f9a (commit)

commit ac73d2895a4e0ee8d57486b5c0fe06ca2f108bca
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Sat Jan 30 13:33:06 2010 +0100

    Don't lock on custom server connection failures
    
    Move the 5 seconds timeout from connect() to start_server() and check
    for return value 0 aswell when receiving an ECONNREFUSED error. Emit a
    "disconnected" signal on ECONNREFUSED instead of EPIPE since going
    through EPIPE would try a reconnection and eventually fail on an
    ECONNREFUSED error.

 src/eataria2.rb |   39 +++++++++++++++++++++------------------
 1 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/eataria2.rb b/src/eataria2.rb
index ddad3ed..7d0ce70 100644
--- a/src/eataria2.rb
+++ b/src/eataria2.rb
@@ -125,14 +125,16 @@ class Eat::Aria2 < GLib::Object
 						STDOUT=>"/dev/null", STDIN=>"/dev/null")
 				Process.detach(@@pid)
 				# Wait for the server to respond properly to requests
-				begin
-					debug("test request")
+				Timeout::timeout(5) do
 					begin
-						result = @@client.call("aria2.getVersion")
-					rescue
-					end
-					sleep 1 if result == nil
-				end while result == nil
+						debug("test request")
+						begin
+							result = @@client.call("aria2.getVersion")
+						rescue
+						end
+						sleep 1 if result == nil
+					end while result == nil
+				end
 				# Store pid in a file
 				begin
 					File.open(@confdir+"/aria2.pid", "w").puts(@@pid)
@@ -157,18 +159,21 @@ class Eat::Aria2 < GLib::Object
 			debug("XMLRPC server didn't support the request")
 			puts e.message
 		rescue Errno::EPIPE => e
-			# Connection interrupted/timed out/server shutdown
+			# Connection interrupted/timed out/server shutdown/etc
+			debug("EPIPE", $!)
+			# Try to reconnect if it was successfully connected previously
+			connect(true) if @is_connected
 			return nil if !@is_connected
-			signal_emit("disconnected")
-			connect(true)
 			result = call(method, args)
 		rescue Errno::ECONNREFUSED => e
-			# Connection refused
-			return nil if start_server < 0
+			# Connection refused/no service listening
+			debug("ECONNREFUSED", $!)
+			signal_emit("disconnected")
+			return nil if start_server <= 0
 			result = call(method, args)
 		rescue Exception => e
 			# Unhandled exception
-			puts $!, e.message
+			debug("unhandled exception in call", $!)
 		end
 		result
 	end
@@ -184,12 +189,11 @@ class Eat::Aria2 < GLib::Object
 		return if @@client and force == false
 		@is_connected = false
 		begin
+			debug("connect")
 			@@client = XMLRPC::Client.new3({:host => @hostname, :path => "/rpc",
 					:port => @port, :user => @user, :password => @password,
 					:timeout => 60})
-			Timeout::timeout(5) do
-				result = call("aria2.getVersion")
-			end
+			result = call("aria2.getVersion")
 			raise Exception.new("Unable to get an appropriate response to our request") if result == nil
 			@version = result["version"]
 			@is_connected = true
@@ -397,7 +401,6 @@ class Eat::Aria2Listener < Eat::Aria2
 				(@downloads - active_downloads).each do |gid|
 					# Get status
 					status = tell_status(gid)
-					status_msg = status["status"]
 					case status["status"]
 						when "complete" then signal_emit("download_completed", gid)
 						when "removed" then signal_emit("download_removed", gid)
@@ -408,7 +411,7 @@ class Eat::Aria2Listener < Eat::Aria2
 							else
 								puts "Unhandled error (%s: %s)" % [gid, status["errorCode"]]
 							end
-						else puts "Unhandled status (%s: %s)" % [gid, status_msg]
+						else puts "Unhandled status (%s: %s)" % [gid, status["status"]]
 					end
 				end
 



More information about the Xfce4-commits mailing list