Module: MiniDisc::Discover::Network
Constant Summary collapse
- DEFAULT_TIMEOUT_LIMIT =
2
Instance Method Summary collapse
- #services(service_type) ⇒ Array<Hash>
- #services_with_timeout(service_type, options = {}, &block) ⇒ Array<Hash>
Instance Method Details
#services(service_type) ⇒ Array<Hash>
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/minidisc/discover/network.rb', line 31 def services(service_type) Thread.abort_on_exception = true replies = {} DNSSD.browse!(service_type) do |reply| replies[reply.name] = reply if !reply.flags.more_coming? available_replies = replies.select do |_, service| service.flags.add? end return available_replies.map do |_, service| resolve = service.resolve { name: service.name, target: resolve.target, port: resolve.port } end end end rescue Errno::EBADF, DNSSD::ServiceNotRunningError [] end |
#services_with_timeout(service_type, options = {}, &block) ⇒ Array<Hash>
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/minidisc/discover/network.rb', line 17 def services_with_timeout(service_type, = {}, &block) timeout = [:timeout] || DEFAULT_TIMEOUT_LIMIT Timeout::timeout(timeout) do result = services(service_type, &block) end rescue Timeout::Error => e result = [] ensure yield(result) if block_given? result end |