mirror of
https://github.com/puppetlabs/vmpooler-provider-vsphere.git
synced 2026-01-26 03:18:41 -05:00
(maint) Use timeout builtin to TCPSocket when opening sockets.
This commit is contained in:
parent
87274a2d51
commit
713a4a2c9d
1 changed files with 7 additions and 9 deletions
|
|
@ -632,15 +632,13 @@ module Vmpooler
|
||||||
|
|
||||||
# This should supercede the open_socket method in the Pool Manager
|
# This should supercede the open_socket method in the Pool Manager
|
||||||
def open_socket(host, domain = nil, timeout = 5, port = 22, &_block)
|
def open_socket(host, domain = nil, timeout = 5, port = 22, &_block)
|
||||||
Timeout.timeout(timeout) do
|
target_host = host
|
||||||
target_host = host
|
target_host = "#{host}.#{domain}" if domain
|
||||||
target_host = "#{host}.#{domain}" if domain
|
sock = TCPSocket.new(target_host, port, connect_timeout: timeout)
|
||||||
sock = TCPSocket.new target_host, port
|
begin
|
||||||
begin
|
yield sock if block_given?
|
||||||
yield sock if block_given?
|
ensure
|
||||||
ensure
|
sock.close
|
||||||
sock.close
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue