[Xfce4-commits] <eatmonkey:aria2-xml-rpc> Thread the connect method of Aria2
Mike Massonnet
noreply at xfce.org
Wed Feb 3 13:48:02 CET 2010
Updating branch refs/heads/aria2-xml-rpc
to 24cadb5a63db003efb16ed100a8fbd0a4887b5b7 (commit)
from 47907622984b2a3edeb85843d1da3c71a623d6f5 (commit)
commit 24cadb5a63db003efb16ed100a8fbd0a4887b5b7
Author: Mike Massonnet <mmassonnet at xfce.org>
Date: Wed Feb 3 13:39:11 2010 +0100
Thread the connect method of Aria2
The connect method is now threaded which makes the GUI immediately
visible and keep it responsive. The connect method also triggers a call
to start_server if needed, still running inside a thread.
src/eat.rb | 4 ++++
src/eataria2.rb | 35 +++++++++++++++++++----------------
2 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/src/eat.rb b/src/eat.rb
index 01857f2..7db2143 100755
--- a/src/eat.rb
+++ b/src/eat.rb
@@ -11,6 +11,10 @@ require "eatmanager"
include Gtk
if __FILE__ == $0
+ if not GLib::Thread.supported?
+ GLib::Thread.init()
+ end
+
aria2 = Eat::Aria2Listener.instance
settings = Eat::Settings.instance
if settings["custom-server"]
diff --git a/src/eataria2.rb b/src/eataria2.rb
index e468677..fe8edc1 100644
--- a/src/eataria2.rb
+++ b/src/eataria2.rb
@@ -4,6 +4,7 @@ require "xmlrpc/client"
require "fileutils"
require "singleton"
require "timeout"
+require "thread"
require "pp"
require "config"
@@ -121,14 +122,14 @@ class Eat::Aria2 < GLib::Object
"--enable-xml-rpc --xml-rpc-listen-port=#{@port} " \
"--conf-path=#{@confdir}/aria2.conf --log=#{@confdir}/aria2.log --log-level=notice " \
"--dht-file-path=#{@confdir}/dht.dat"
- debug("start server", command)
@@pid = Process.spawn(command, :pgroup=>true, :chdir=>ENV['HOME'],
STDOUT=>"/dev/null", STDIN=>"/dev/null")
Process.detach(@@pid)
+ debug("started server", command, @@pid)
# Wait for the server to respond properly to requests
+ debug("waiting for a first response...")
Timeout::timeout(5) do
begin
- debug("test request")
begin
result = @@client.call("aria2.getVersion")
rescue
@@ -190,20 +191,22 @@ class Eat::Aria2 < GLib::Object
def connect(force=false)
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})
- result = call("aria2.getVersion")
- raise Exception.new("Unable to connect to aria2 XML-RPC server") if result == nil
- @version = result["version"]
- @is_connected = true
- signal_emit("connected")
- rescue Exception => e
- @@client = nil
- puts "Can't establish a connection"
- debug(e.message)
+ Thread.new do
+ begin
+ debug("connect")
+ @@client = XMLRPC::Client.new3({:host => @hostname, :path => "/rpc",
+ :port => @port, :user => @user, :password => @password,
+ :timeout => 60})
+ result = call("aria2.getVersion")
+ raise Exception.new("Unable to connect to aria2 XML-RPC server") if result == nil
+ @version = result["version"]
+ @is_connected = true
+ signal_emit("connected")
+ rescue Exception => e
+ @@client = nil
+ puts "Can't establish a connection"
+ debug(e.message)
+ end
end
end
More information about the Xfce4-commits
mailing list