add timeout

This commit is contained in:
nishiki 2014-08-31 10:59:33 +02:00
parent 4a564dd07e
commit 1390850e18

View file

@ -11,6 +11,7 @@ module MPW
require 'i18n' require 'i18n'
require 'socket' require 'socket'
require 'json' require 'json'
require 'timeout'
class MPWSync class MPWSync
@ -37,9 +38,20 @@ module MPW
@password = password @password = password
@suffix = path @suffix = path
Timeout.timeout(10) do
begin
TCPSocket.open(@host, @port) do TCPSocket.open(@host, @port) do
puts 'testi2'
@enable = true @enable = true
end end
rescue Errno::ENETUNREACH
retry
end
end
rescue Timeout::Error
puts 'timeout'
@error_msg = "#{I18n.t('error.timeout')}\n#{e}"
@enable = false
rescue Exception => e rescue Exception => e
@error_msg = "#{I18n.t('error.sync.connection')}\n#{e}" @error_msg = "#{I18n.t('error.sync.connection')}\n#{e}"
@enable = false @enable = false