do case state when :start then when :v4w then when :v6c, :v4c, :v46c then when :v46w then when :success then when :failure then when :timeout then end end end ͜Ε·Ͱͷ͋Β͢͡4PDLFUUDQͷ࣮ શମ૾ ໊લղܾΛ։࢝͢Δ IPv6ͷ໊લղܾྃΛ50msػ͢Δ ଓΛ։࢝͢Δ ଓঢ়ଶͷ֬ఆͱ໊લղܾͷྃΛػ͢Δ ଓʹޭͨ͠ιέοτΛฦ͢ ྫ֎Λൃੜͤ͞Δ λΠϜΞτྫ֎Λൃੜͤ͞Δ ࣮ʹ͋ͨͬͯ,FSOFMMPPQͱDBTFΛ Έ߹ΘͤΔ͜ͱͰઌ΄Ͳͷঢ়ଶભҠΛදݱ͢Δ
do case state when :start then when :v4w then when :v6c, :v4c, :v46c then when :v46w then when :success then when :failure then when :timeout then end end end ͜Ε·Ͱͷ͋Β͢͡4PDLFUUDQͷ࣮ શମ૾ ໊લղܾΛ։࢝͢Δ IPv6ͷ໊લղܾྃΛ50msػ͢Δ ଓΛ։࢝͢Δ ଓঢ়ଶͷ֬ఆͱ໊લղܾͷྃΛػ͢Δ ଓʹޭͨ͠ιέοτΛฦ͢ ྫ֎Λൃੜͤ͞Δ λΠϜΞτྫ֎Λൃੜͤ͞Δ ϧʔϓͰඞͣʮݱࡏͷঢ়ଶʯ͕ઃఆ͞Ε͍ͯΔɻ ঢ়ଶʹԠͯ͡ߦ͏͖ॲཧΛ࣮ߦ͠ɺ ࣍ͷঢ়ଶΛઃఆ͠ɺ࣍ͷϧʔϓʹਐΉ ֤ঢ়ଶͰߦ͏ॲཧ TUBUFʮݱࡏͷঢ়ଶʯΛཧ͢Δม ॳظঢ়ଶͱͯ͠TUBSUΛઃఆ ݱࡏͷঢ়ଶ
# ... family_name, res = hostname_resolution_queue.get # ... state = case family_name when :ipv6 then :v6c when :ipv4 then :v4w end selectable_addrinfos.add(family_name, res) # ... next (hostname_resolution_waiting, nil, nil, remaining) ͜Ε·Ͱͷ͋Β͢͡4PDLFUUDQͷ࣮ TUBSU TUBSU*0TFMFDUΛ༻໊͍ͯલղܾ͕ྃ͢Δ·Ͱ جຊతʹ ແظݶͰػ͢Δ ͲͪΒ͔ͷ໊લղܾ͕ྃ͢Δ·ͰॲཧΛϒϩοΫ ˞໊લղܾΛ։࢝͢ΔͨΊͷঢ়ଶ ϢʔβʔࢦఆͷλΠϜΞτ ࢦఆ͕ͳ͍߹OJMແظݶ ࣍ͷঢ়ଶΛܾఆ ࣍ͷঢ়ଶ ໊લղܾͷ݁ՌΛऔಘ
if ipv6_resolved family_name, res = hostname_resolution_queue.get selectable_addrinfos.add(family_name, res) unless res.is_a? E state = :v46c else state = :v4c end next WX*0TFMFDUΛ༻͍ͯ*1Wͷ໊લղܾΛNTػɻ ػ࣌ؒʹ*1Wͷ໊લղܾ͕͔ྃͨ͠ʹΑͬͯɺ ࣍ͷঢ়ଶΛஅ͢Δɻ (hostname_resolution_waiting, nil, nil, RESOLUTION_DELAY) ˞ઌʹ*1WΛղܾͰ͖ͨ߹ʹ*1Wͷ໊લղܾΛػ͢ΔͨΊͷঢ়ଶ Exception NT ࣍ͷঢ়ଶ ࣍ͷঢ়ଶΛܾఆ *1Wͷ໊લղܾ͕ྃ͢Δ͔λΠϜΞτ͢Δ·ͰॲཧΛϒϩοΫ
loop do case state when :start then when :v4w then when :v6c, :v4c, :v46c then when :v46w then when :success then when :failure then when :timeout then end end end ໊લղܾΛ։࢝͢Δ IPv6ͷ໊લղܾྃΛػ͢Δ ଓΛ։࢝͢Δ ଓঢ়ଶͷ֬ఆͱ໊લղܾͷྃΛػ͢Δ ଓʹޭͨ͠ιέοτΛฦ͢ ྫ֎Λൃੜͤ͞Δ λΠϜΞτྫ֎Λൃੜͤ͞Δ
# ... family_name, res = hostname_resolution_queue.get # ... state = case family_name when :ipv6 then :v6c when :ipv4 then :v4w end selectable_addrinfos.add(family_name, res) # ... next (hostname_resolution_waiting, nil, nil, remaining) ઌʹղܾͰ͖ͨΞυϨεϑΝϛϦʹΑͬͯ࣍ͷঢ়ଶΛܾఆ ˞໊લղܾΛ։࢝͢ΔͨΊͷঢ়ଶ TUBSUઌʹ໊લղܾ͕ྃͨ͠ͷ͕*1Wͩͬͨͷ͔ɺ *1Wͩͬͨͷ͔ʹΑͬͯɺ࣍ͷঢ়ଶΛஅ͍ͯ͠Δ ʮ࣮Λঢ়ଶભҠʹدͤ͗͢ʯͷྫTUBSU ໊લղܾͷ݁ՌΛऔಘ
# ... family_name, res = hostname_resolution_queue.get # ... state = case family_name when :ipv6 then :v6c when :ipv4 then :v4w end selectable_addrinfos.add(family_name, res) # ... next (hostname_resolution_waiting, nil, nil, remaining) ͜ͷ࣌Ͱ*1W*1Wͱʹ ໊લղܾ͕͍ྃͯͨ͠ΒͲ͏ͳΔ ˞໊લղܾΛ։࢝͢ΔͨΊͷঢ়ଶ ʮ࣮Λঢ়ଶભҠʹدͤ͗͢ʯͷྫTUBSU
# ... family_name, res = hostname_resolution_queue.get # ... state = case family_name when :ipv6 then :v6c when :ipv4 then :v4w end selectable_addrinfos.add(family_name, res) # ... next ʮ࣮Λঢ়ଶભҠʹدͤ͗͢ʯͷྫTUBSU ϝΠϯεϨου*0TFMFDUͷػΛղআ͠ɺΩϡʔͷ ઌ಄͔Βͻͱͭऔಘ͢Δ ઌ಄*1Wͷ໊લղܾ݁Ռ ϝΠϯεϨουऔಘͰ͖ͨΞυϨεϑΝϛϦ͔Β ࣍ͷঢ়ଶΛஅ͢ΔͨΊɺ͜ͷ߹WXભҠ͢Δɻ (hostname_resolution_waiting, nil, nil, remaining) Ωϡʔͷઌ಄Λऔಘ औಘͨ͠ΞυϨεϑΝϛϦ͕*1WͳͷͰɺ ࣍ͷঢ়ଶΛWXͱஅͯ͠͠·͏ ˞໊લղܾΛ։࢝͢ΔͨΊͷঢ়ଶ
family_name, res = hostname_resolution_queue.get selectable_addrinfos.add(family_name, res) unless res.is_a? E state = :v46c else state = :v4c end next ˞ઌʹ*1WΛղܾͰ͖ͨ߹ʹ*1Wͷ໊લղܾΛػ͢ΔͨΊͷঢ়ଶ WXʹͯɺ*1W͢ͰʹղܾࡁΈͰ͋ΔʹؔΘΒͣ *1Wͷ໊લղܾΛػ͢ΔͨΊʹ*0TFMFDUΛݺͼग़͢ ෆཁͳ*0TFMFDUͷݺͼग़͕͠ൃੜ͍ͯ͠Δ ͢Ͱʹ*1WղܾࡁΈͳͷʹɺෆཁʹ*0TFMFDUΛݺͼग़͍ͯ͠Δ (hostname_resolution_waiting, nil, nil, RESOLUTION_DELAY) ʮ࣮Λঢ়ଶભҠʹدͤ͗͢ʯͷྫWX Ωϡʔͷઌ಄Λऔಘ Exception
IO.select( # ... family_name, res = hostname_resolution_queue.get # ... state = case family_name when :ipv6 then :v6c when :ipv4 then :v4w end # ... next (hostname_resolution_waiting, nil, nil, remaining) ঢ়ଶભҠΛݟͨͷ··࣮ͨ݁͠ՌɺҰͭͷঢ়ଶ͔Β ඞͣҰͭͷঢ়ଶભҠ͢Δͱ͍͏લఏͷ࣮ʹͳ͍ͬͯΔɻ Ұํɺ࣮ࡍʹ͜ͷྫͷΑ͏ʹʮঢ়ଶͷॏͶ߹Θͤʯ͕ ൃੜ͠͏Δɻ TUBSU͔ΒWDʹભҠ͢ΔͨΊͷ݅ͱ WXʹભҠ͢ΔͨΊͷ͕݅ಉ࣌ʹຬͨ͞Ε͏Δ Ұͭͷঢ়ଶ͔ΒඞͣҰͭͷঢ়ଶભҠ͢Δ ʮঢ়ଶͷॏͶ߹Θͤʯ͕ൃੜ͢ΔՄೳੑ͕ ߟྀ͞Ε͍ͯͳ͍ ˞໊લղܾΛ։࢝͢ΔͨΊͷঢ়ଶ
end ໊લղܾͷ։࢝ if ଓ։࢝ͷ݅Λຬ͍ͨͯ͠Δ then ଓΛ։࢝ IO.select(<໊લղܾ>, <ଓ>, nil, <λΠϜΞτ>) if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn) if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ if ࣍ͷϧʔϓʹೖΔ͜ͱ͕Ͱ͖ͳ͍ then ྫ֎Λൃੜͤ͞Δ λΠϜΞτมͷॳظԽ
ଓ։࢝ͷ݅Λຬ͍ͨͯ͠Δ then ଓΛ։࢝ IO.select(<໊લղܾ>, <ଓ>, nil, <λΠϜΞτ>) if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn) if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ if ࣍ͷϧʔϓʹೖΔ͜ͱ͕Ͱ͖ͳ͍ then ྫ֎Λൃੜͤ͞Δ λΠϜΞτมͷॳظԽ )&WରԠ4PDLFUUDQ վ ͷ֓؍ ϧʔϓͷͨͼʹ্͔Βॱʹ࣮ߦ͞ΕΔ ঢ়ଶཧΛΊͨ͜ͱʹΑΓϧʔϓͷDBTF͕ফ͑ ΘΓʹJGจʹΑΔ݅ذ͕Ճ͞Ε͍ͯΔ
!connection_attempt_delay_expires_at while (addrinfo = resolution_store.get_addrinfo) # end # ... end end ϧʔϓͷதͰ·ͣ ʮଓ։࢝ͷ݅Λຬ͍ͨͯ͠Δ͔Ͳ͏͔ʯΛ֬ೝ͢Δ ɾղܾࡁΈͷΞυϨεͷࡏݿ͕͋Δ͜ͱ ɾ͔ͭ*1Wͷ໊લղܾΛػதͰͳ͍͜ͱ ɾ͔ͭଓ։࢝ͷػதͰͳ͍͜ͱ ଓΛ։࢝͢ΔͨΊͷॲཧ ϧʔϓΛ։࢝ ଓ։࢝ͷ݅Λຬ͍ͨͯ͠Δ
connecting_sockets.keys, is_windows_environment ? connecting_sockets.keys : nil, second_to_timeout(current_clock_time, ends_at), ) # ... end )&WରԠ4PDLFUUDQ վ ͷ໊࣮લղܾͱଓͷػ ଓঢ়ଶͷ֬ఆ·໊ͨલղܾͷྃΛػ ଓ͍ͯɺ*0TFMFDUΛ༻͍ͯଓঢ়ଶͷ֬ఆ͔ ໊લղܾͷྃΛػ͢Δ มߋલͷ4PDLFUUDQͷWXͰߦ͍ͬͯͨॲཧͱಉ͡ if ଓ։࢝ͷ݅Λຬ͍ͨͯ͠Δ then ଓΛ։࢝ if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn) if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ
family_name, result = family_and_result if result.is_a? Exception # ... else resolution_store.add_resolved(family_name, result) end # ... end end # ... end ͞Βʹ*0TFMFDUͷ࣮ߦ݁Ռͱͯ͠ ʮ໊લղܾ͕͍ྃͯ͠Δ͔Ͳ͏͔ʯΛ֬ೝ )&WରԠ4PDLFUUDQ վ ͷ໊࣮લղܾͷྃ ໊લղܾ͕ྃͨ͠ IO.select(<໊લղܾ>, <ଓ>, nil, <λΠϜΞτ>)
raise last_error end if (expired?(now, user_specified_resolv_timeout_at) || ...) && (expired?(now, user_specified_connect_timeout_at) || ...) raise Errno::ETIMEDOUT, 'user specified timeout' end end end ϧʔϓͷ࠷ޙʹɺ ʮ࣍ͷϧʔϓʹೖΔ͜ͱ͕Ͱ͖Δ͔Ͳ͏͔ʯ֬ೝ )&WରԠ4PDLFUUDQ վ ͷ࣮࣍ͷϧʔϓ ࣍ͷϧʔϓʹೖΔ͜ͱ͕Ͱ͖Δ if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn)
raise last_error end if (expired?(now, user_specified_resolv_timeout_at) || ...) && (expired?(now, user_specified_connect_timeout_at) || ...) raise Errno::ETIMEDOUT, 'user specified timeout' end end end ɾղܾࡁΈͷΞυϨεͷࡏݿ͕ͳ͍ ɾ͔ͭɺଓதͷιέοτ͕ͳ͍ ɾ͔ͭɺͯ͢ͷ໊લղܾ͕ऴΘ͍ͬͯΔ߹ ͜ΕҎ্࣮ߦͰ͖Δॲཧ͕ͳ͍ͨΊɺྫ֎Λൃੜͤ͞Δ )&WରԠ4PDLFUUDQ վ ͷ࣮࣍ͷϧʔϓ if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn) ͜ΕҎ্࣮ߦͰ͖Δॲཧ͕ͳ͍ ࠷ޙʹิͨ͠ΤϥʔͰྫ֎Λൃੜͤ͞Δ
raise last_error end if (expired?(now, user_specified_resolv_timeout_at) || ...) && (expired?(now, user_specified_connect_timeout_at) || ...) raise Errno::ETIMEDOUT, 'user specified timeout' end end end ϢʔβʔࢦఆͷλΠϜΞτ͕ա͍ͯ͠Δ߹ɺ λΠϜΞτΛද͢ྫ֎Λൃੜͤ͞Δɻ )&WରԠ4PDLFUUDQ վ ͷ࣮࣍ͷϧʔϓ ϢʔβʔࢦఆͷλΠϜΞτΛաࡁΈ λΠϜΞτΛද͢ྫ֎Λൃੜͤ͞Δ if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn)
raise last_error end if (expired?(now, user_specified_resolv_timeout_at) || ...) && (expired?(now, user_specified_connect_timeout_at) || ...) raise Errno::ETIMEDOUT, 'user specified timeout' end end end ͦΕҎ֎ͷ߹࣍ͷϧʔϓʹਐΉ 5PCFDPOUJOVFE )&WରԠ4PDLFUUDQ վ ͷ࣮࣍ͷϧʔϓ ࣍ͷϧʔϓ if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn)
ଓ։࢝ͷ݅Λຬ͍ͨͯ͠Δ then ଓΛ։࢝ IO.select(<໊લղܾ>, <ଓ>, nil, <λΠϜΞτ>) if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn) if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ if ࣍ͷϧʔϓʹೖΔ͜ͱ͕Ͱ͖ͳ͍ then ྫ֎Λൃੜͤ͞Δ λΠϜΞτมͷॳظԽ )&WରԠ4PDLFUUDQ վ ɿΓͷ՝
ଓ։࢝ͷ݅Λຬ͍ͨͯ͠Δ then ଓΛ։࢝ IO.select(<໊લղܾ>, <ଓ>, nil, <λΠϜΞτ>) if ଓঢ়ଶ͕֬ఆͨ͠ιέοτ͕͋Δ then ଓ֬ೝɹ(ޭ͍ͯͨ͠Βreturn) if ໊લղܾ͕ྃ then ղܾࡁΈͷIPΞυϨεΛอଘ if ࣍ͷϧʔϓʹೖΔ͜ͱ͕Ͱ͖ͳ͍ then ྫ֎Λൃੜͤ͞Δ λΠϜΞτมͷॳظԽ )&WରԠ4PDLFUUDQ վ ࠓͦ͜