netsoul 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f924c44cf5fac236ba67f786746bd346324ab7a
4
- data.tar.gz: 613d0e50f6b7f6f612571972eda5b755c363da08
3
+ metadata.gz: a04003bb02b749e6d569cc7958e4b14155f84dde
4
+ data.tar.gz: 59c4229498648f7a182682d30b0a1352aae48b2e
5
5
  SHA512:
6
- metadata.gz: 394843b7c4b32c47bfb16e3ef2e1e38e6ed4aa3e1b08c07d716be3443ea1797376801c79ac16f5a2d23db1ff99dfa8ca737e4ede8abdecadc066f5fe6b435bf0
7
- data.tar.gz: f3a73c0fb7bd3b8fb8d7cf4374915f4abe224c23d948b8c5dd677f9d2c2a7328424aad5d34cd991b410e58ad44d558d980c906c14c1a0d057e1d74991ae7e6cf
6
+ metadata.gz: 639b6d93e72d9a9e9d9adb8472ba70eade8f37ca188abe4dcd4876093caf585faec60f8ff34b57d93bb1f01e6631a48b34d296524ace1389da9af3f68d897fc2
7
+ data.tar.gz: cd6256097bf4783465d8714097938d7473267125024d4ba456fd96640ab70161a33070d43c25f4c2ba0fc4d032eb0c1ce208e84cbeaa9b73c43b040a5380d5c5
data/bin/netsoul-ruby CHANGED
@@ -13,6 +13,9 @@ module Netsoul
13
13
  class Client
14
14
  include Logging
15
15
 
16
+ SOCKET_READ_TIMEOUT = 10 * 60
17
+ SOCKET_WRITE_TIMEOUT = 10
18
+
16
19
  attr_reader :started
17
20
 
18
21
  def initialize(*args)
@@ -46,10 +49,8 @@ module Netsoul
46
49
  def connect
47
50
  @sock = TCPSocket.new(@config.server_host, @config.server_port)
48
51
  fail Netsoul::SocketError, 'Could not open a socket. Connection is unavailable.'.freeze unless @sock
49
-
50
52
  _cmd, _socket_num, md5_hash, client_ip, client_port, _server_timestamp = sock_get.split
51
53
  @config.build_user_connection_info md5_hash: md5_hash, client_ip: client_ip, client_port: client_port
52
-
53
54
  auth_ag
54
55
  auth_method
55
56
  auth_status
@@ -63,12 +64,16 @@ module Netsoul
63
64
  end
64
65
 
65
66
  def sock_send(str)
67
+ _, sock = IO.select(nil, [@sock], nil, SOCKET_WRITE_TIMEOUT)
68
+ fail Netsoul::SocketError, 'Timeout or fail on write socket' if sock.nil? || sock.empty?
69
+ sock.first.puts str
66
70
  log :info, "[send] #{str.chomp}"
67
- @sock.puts str
68
71
  end
69
72
 
70
73
  def sock_get
71
- res = @sock.gets
74
+ sock, = IO.select([@sock], nil, nil, SOCKET_READ_TIMEOUT)
75
+ fail Netsoul::SocketError, 'Timeout or fail on read socket' if sock.nil? || sock.empty?
76
+ res = sock.first.gets
72
77
  log :info, "[get ] #{res.chomp}"
73
78
  res
74
79
  end
@@ -113,8 +118,8 @@ unless options.include?(:config)
113
118
  end
114
119
 
115
120
  retry_count = 10
116
- retry_wait_time = 1.0
117
- RETRY_WAIT_FACTOR = 1.25 # Each time retry is called in Exception, current 'retry_wait_time' is increased with this factor
121
+ retry_wait_time = 10.0
122
+ RETRY_WAIT_FACTOR = 1.50 # Each time retry is called in Exception, current 'retry_wait_time' is increased with this factor
118
123
  begin
119
124
  c = Netsoul::Client.new options[:user_opts]
120
125
  c.connect
@@ -127,15 +132,18 @@ begin
127
132
  sleep 1
128
133
  end
129
134
  end
135
+ rescue Interrupt
136
+ c.disconnect if c.started
137
+ puts '!!! [SIGINT] !!!'
138
+ exit 42
130
139
  rescue => e
131
- puts "[ERROR]: #{e}"
132
- puts "[RETRY_COUNT]: #{retry_count}"
140
+ puts "[ERROR]: #{e} - [RETRY_COUNT]: #{retry_count}"
133
141
  c.disconnect
134
142
  c = nil
135
143
  if retry_count > 0
136
144
  retry_count -= 1
137
145
  retry_wait_time *= RETRY_WAIT_FACTOR
138
- sleep retry_wait_time
139
- retry
146
+ sleep(retry_wait_time) && retry
140
147
  end
148
+ exit 42
141
149
  end
@@ -1,3 +1,3 @@
1
1
  module Netsoul
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsoul
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kakesa