Method: Calabash::Android::Operations::Device#default_server_port

Defined in:
lib/calabash-android/operations.rb

#default_server_portObject


529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
# File 'lib/calabash-android/operations.rb', line 529

def default_server_port
  require 'yaml'
  File.open(File.expand_path(server_port_configuration), File::RDWR|File::CREAT) do |f|
    f.flock(File::LOCK_EX)
    state = YAML::load(f) || {}
    ports = state['server_ports'] ||= {}
    return ports[serial] if ports.has_key?(serial)

    port = 34777
    port += 1 while ports.has_value?(port)
    ports[serial] = port

    f.rewind
    f.write(YAML::dump(state))
    f.truncate(f.pos)

    log "Persistently allocated port #{port} to #{serial}"
    return port
  end
end