mirror of
https://github.com/nishiki/manage-password.git
synced 2025-03-20 21:34:35 +00:00
add timeout
This commit is contained in:
parent
4a564dd07e
commit
1390850e18
1 changed files with 17 additions and 5 deletions
|
@ -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
|
||||||
|
|
||||||
TCPSocket.open(@host, @port) do
|
Timeout.timeout(10) do
|
||||||
@enable = true
|
begin
|
||||||
|
TCPSocket.open(@host, @port) do
|
||||||
|
puts 'testi2'
|
||||||
|
@enable = true
|
||||||
|
end
|
||||||
|
rescue Errno::ENETUNREACH
|
||||||
|
retry
|
||||||
|
end
|
||||||
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
|
||||||
|
@ -58,9 +70,9 @@ module MPW
|
||||||
msg = nil
|
msg = nil
|
||||||
TCPSocket.open(@host, @port) do |socket|
|
TCPSocket.open(@host, @port) do |socket|
|
||||||
send_msg = {:action => 'get',
|
send_msg = {:action => 'get',
|
||||||
:gpg_key => @gpg_key,
|
:gpg_key => @gpg_key,
|
||||||
:password => @password,
|
:password => @password,
|
||||||
:suffix => @suffix}
|
:suffix => @suffix}
|
||||||
|
|
||||||
socket.puts send_msg.to_json
|
socket.puts send_msg.to_json
|
||||||
msg = JSON.parse(socket.gets)
|
msg = JSON.parse(socket.gets)
|
||||||
|
|
Loading…
Add table
Reference in a new issue