[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Join connection Thread in call()

Mike Massonnet noreply at xfce.org
Sat Feb 27 00:44:04 CET 2010


Updating branch refs/heads/aria2-xml-rpc
         to e17c172ea6ceb9f2afe4d406556f811ffe7b1f52 (commit)
       from 657599d06aa4d08c20969f8fd0261352559a0333 (commit)

commit e17c172ea6ceb9f2afe4d406556f811ffe7b1f52
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Sat Feb 27 00:40:21 2010 +0100

    Join connection Thread in call()
    
    When running an Aria2 object, it has to connect() prior of using call()
    methods, and since connecting may result in dispatched call()s, the
    connection Thread is joined.
    
    Add STDERR=/dev/null for spawning a command.

 src/compat18.rb    |    1 +
 src/eataria2.rb    |   37 ++++++++++++++++++++-----------------
 src/eatmanager.rb  |    2 ++
 3 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/src/compat18.rb b/src/compat18.rb
old mode 100644
new mode 100755
index 3768ae5..194aa9f
--- a/src/compat18.rb
+++ b/src/compat18.rb
@@ -21,6 +21,7 @@ def Process::spawn(command, *)
 	pid = fork do
 		FileUtils.chdir(ENV['HOME'])
 		STDOUT.reopen('/dev/null')
+		STDERR.reopen('/dev/null')
 		STDIN.reopen('/dev/null')
 		Process.setpgid(0, 0)
 		exec command
diff --git a/src/config.rb b/src/config.rb
old mode 100644
new mode 100755
diff --git a/src/eataria2.rb b/src/eataria2.rb
old mode 100644
new mode 100755
index 5d7fc72..1c09b3b
--- a/src/eataria2.rb
+++ b/src/eataria2.rb
@@ -88,6 +88,7 @@ class Eat::Aria2 < GLib::Object
 		@use_local_server = true
 		@version = "n/a"
 		@@client = nil if !defined? @@client
+		@connect_thread = nil
 		@shutdown_thread = nil
 
 		if !defined? @@pid
@@ -170,7 +171,7 @@ class Eat::Aria2 < GLib::Object
 =end
 	def spawn_server(command)
 		pid = Process.spawn(command, :pgroup=>true, :chdir=>ENV['HOME'],
-				STDOUT=>"/dev/null", STDIN=>"/dev/null")
+				STDOUT=>"/dev/null", STDERR=>"/dev/null", STDIN=>"/dev/null")
 		Process.detach(pid)
 		# Wait for the server to respond properly to requests
 		debug("waiting for a first response...")
@@ -192,6 +193,8 @@ class Eat::Aria2 < GLib::Object
 	Make an XML-RPC call to the server. Try to connect if the connection is broken.
 =end
 	def call(method, *args)
+		@connect_thread.join if @connect_thread != nil and Thread.current != @connect_thread
+		return if @@client == nil
 		begin
 			result = @@client.call(method, *args)
 		rescue XMLRPC::FaultException => e
@@ -229,7 +232,7 @@ class Eat::Aria2 < GLib::Object
 	def connect(force=false)
 		return if @@client and force == false
 		@is_connected = false
-		Thread.new do
+		@connect_thread = Thread.new do
 			@shutdown_thread.join if @shutdown_thread != nil
 			begin
 				debug("connect")
@@ -678,22 +681,22 @@ end
 
 if __FILE__ == $0
 	aria2 = Eat::Aria2.new
-	exit if !aria2.is_connected
-	puts "Version: aria2 "+aria2.version
-	#aria2.add_uri(["http://dlc.sun.com/torrents/info/osol-0906-x86.iso.torrent"])
+	aria2.connect
 	begin
-		aria2.tell_active.each do |res|
-			gid = res["gid"]
-			puts " *** Set download max rate to 16KB ***"
-			aria2.change_options(gid, "max-download-limit" => "16000")
-			puts " *** Get status ***"
-			pp aria2.tell_status(gid)
-			puts " *** Get uris ***"
-			pp aria2.get_uris(gid)
-			puts " *** Get files ***"
-			pp aria2.get_files(gid)
-			puts " *** Get peers ***"
-			pp aria2.get_peers(gid).length
+		if aria2.is_connected
+			aria2.tell_active.each do |res|
+				gid = res["gid"]
+				puts " *** Set download max rate to 16KB ***"
+				aria2.change_options(gid, "max-download-limit" => "16000")
+				puts " *** Get status ***"
+				pp aria2.tell_status(gid)
+				puts " *** Get uris ***"
+				pp aria2.get_uris(gid)
+				puts " *** Get files ***"
+				pp aria2.get_files(gid)
+				puts " *** Get peers ***"
+				pp aria2.get_peers(gid).length
+			end
 		end
 		sleep 5
 	end while true
diff --git a/src/eatmanager.rb b/src/eatmanager.rb
old mode 100644
new mode 100755
index f94d730..3ffab02
--- a/src/eatmanager.rb
+++ b/src/eatmanager.rb
@@ -439,6 +439,8 @@ end
 
 
 if __FILE__ == $0
+	aria2 = Eat::Aria2Listener.instance
+	aria2.connect
 	manager = Eat::Manager.new
 	manager.show
 	main
diff --git a/src/eatsettings.rb b/src/eatsettings.rb
old mode 100644
new mode 100755



More information about the Xfce4-commits mailing list