Module: Cukunity::RequestLineResponseClientMethods

Includes:
Utils
Included in:
Android::MonkeyClient, Unity::ClientMethods
Defined in:
lib/cukunity/request_line_response_client_methods.rb

Constant Summary collapse

DEFAULT_TIMEOUT =
30

Instance Method Summary collapse

Methods included from Utils

#check_timeout, #merge_options, #restrict_options, #to_options, #wait_connectivity

Instance Method Details

#request(line, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cukunity/request_line_response_client_methods.rb', line 9

def request(line, options = {})
  options = merge_options(options, { :max_time => DEFAULT_TIMEOUT,
                                     :quit => false, :retry => true })
  connect
  response = nil
  begin
    raise Exception::MobileDeviceTimeout.new(cmd) if check_timeout(options[:max_time]) do
      @socket.puts(line)
      @socket.flush
      return if options[:quit]
      response = @socket.gets
      break unless response.nil? and options[:retry]
      close
      sleep 0.1
      connect
      false
    end
  rescue Errno::ECONNRESET
    return if options[:quit]
    close
    if options[:retry]
      connect
      retry
    end
  rescue Errno::EPIPE
    return if options[:quit]
    close
    if options[:retry]
      connect
      retry
    end
  end
  if block_given?
    yield response
  else
    response
  end
end