Module: MogileFS::Network
- Includes:
- Util
- Defined in:
- lib/mogilefs/network.rb
Constant Summary
Constants included from Util
Instance Method Summary collapse
-
#verify_uris(uris = [], expect = '200', timeout = 2.00) ⇒ Object
given an array of URIs, verify that at least one of them is accessible with the expected HTTP code within the timeout period (in seconds).
Methods included from Util
Instance Method Details
#verify_uris(uris = [], expect = '200', timeout = 2.00) ⇒ Object
given an array of URIs, verify that at least one of them is accessible with the expected HTTP code within the timeout period (in seconds).
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mogilefs/network.rb', line 8 def verify_uris(uris = [], expect = '200', timeout = 2.00) uri_socks = {} # first, we asynchronously connect to all of them uris.each do |uri| sock = Socket.mogilefs_new_nonblock(uri.host, uri.port) rescue next uri_socks[sock] = uri end # wait for at least one of them to finish connecting and send # HTTP requests to the connected ones sockets, timeout = get_writable_set(uri_socks, timeout) # Await a response from the sockets we had written to, we only need one # valid response, but we'll take more if they return simultaneously sockets[0] ? get_readable_uris(sockets, uri_socks, expect, timeout) : [] ensure uri_socks.keys.each { |sock| sock.close rescue nil } end |