lib/deluge/rpc/connection.rb in deluge-rpc-0.2.0 vs lib/deluge/rpc/connection.rb in deluge-rpc-0.2.2

- old
+ new

@@ -65,11 +65,11 @@ true end def authenticate(login, password) - self.call(DAEMON_LOGIN, login, password) + self.call(DAEMON_LOGIN, [login, password, {'client_version' => Deluge::Rpc::VERSION.to_s}]) end def method_list self.call(DAEMON_METHOD_LIST) end @@ -91,11 +91,14 @@ def call(method, *args) raise "Not connected!" unless @connection kwargs = {} - kwargs = args.pop if args.size == 1 && args.last.is_a?(Hash) + if args.size == 1 && args[0].last.is_a?(Hash) + kwargs = args[0].pop + args = args[0] + end future = Concurrent::IVar.new request_id = @request_id.increment @messages[request_id] = future @@ -187,10 +190,13 @@ # Read message header protocol_version, buffer_size = socket.readpartial(5).unpack('CN') raise('Received response with unknown protocol_version=' + protocol_version) if protocol_version != PROTOCOL_VERSION - raw = socket.readpartial(buffer_size) + # a big response requires some extra reads because deluged may be + # slow to generate and send all the data through the socket + raw += socket.readpartial(buffer_size - raw.bytesize) while raw.bytesize < buffer_size + raw = Zlib::Inflate.inflate(raw) parse_packets(raw) end