Updating branch refs/heads/aria2-xml-rpc
         to 7b351763424241bfd2030b1932117e6f51bf1055 (commit)
       from 7f672e1e19dfed24056a92be0492225f38e7c776 (commit)

commit 7b351763424241bfd2030b1932117e6f51bf1055
Author: Mike Massonnet <[email protected]>
Date:   Sat Feb 6 17:59:25 2010 +0100

    Add support for local sever with aria2 < 1.7
    
    Try to spawn a server with command arguments from aria2 1.7+ and if it
    doesn't answer to XML-RPC requests, re-run a server with lesser
    arguments that work with aria2 1.4/1.6.

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

diff --git a/src/eataria2.rb b/src/eataria2.rb
index 0682f46..28b2d55 100644
--- a/src/eataria2.rb
+++ b/src/eataria2.rb
@@ -124,24 +124,22 @@ class Eat::Aria2 < GLib::Object
                                # Cleanup log file
                                FileUtils.rm(@confdir+"/aria2.log", :force => 
true)
                                # Launch aria2c process
-                               command = "aria2c --disable-ipv6=true " \
-                                       "--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"
-                               @@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
-                                               begin
-                                                       result = 
@@client.call("aria2.getVersion")
-                                               rescue
-                                               end
-                                               sleep 1 if result == nil
-                                       end while result == nil
+                               begin
+                                       command = "aria2c --disable-ipv6=true " 
\
+                                               "--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"
+                                       @@pid = spawn_server(command)
+                               rescue Timeout::Error
+                               begin
+                                       # Retry with fewer arguments for aria2 
< 1.7
+                                       command = "aria2c --enable-xml-rpc 
--xml-rpc-listen-all --xml-rpc-listen-port...@port} " \
+                                               
"--conf-path...@confdir}/aria2.conf --log...@confdir}/aria2.log 
--log-level=notice"
+                                       @@pid = spawn_server(command)
+                               rescue Timeout::Error
+                                       @@pid = 0
+                                       raise "Failed to get positive response 
from aria2"
+                               end
                                end
                                # Store pid in a file
                                begin
@@ -159,6 +157,25 @@ class Eat::Aria2 < GLib::Object
                end
        end
 
+       def spawn_server(command)
+               pid = Process.spawn(command, :pgroup=>true, :chdir=>ENV['HOME'],
+                               STDOUT=>"/dev/null", STDIN=>"/dev/null")
+               Process.detach(pid)
+               # Wait for the server to respond properly to requests
+               debug("waiting for a first response...")
+               Timeout::timeout(5) do
+                       begin
+                               begin
+                                       result = 
@@client.call("aria2.getVersion")
+                               rescue
+                               end
+                               sleep 1 if result == nil
+                       end while result == nil
+               end
+               debug("started server", command, pid)
+               pid
+       end
+
        def call(method, *args)
                begin
                        result = @@client.call(method, *args)
_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to