netsoul 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/netsoul-ruby +18 -10
- data/lib/netsoul/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a04003bb02b749e6d569cc7958e4b14155f84dde
|
4
|
+
data.tar.gz: 59c4229498648f7a182682d30b0a1352aae48b2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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 =
|
117
|
-
RETRY_WAIT_FACTOR = 1.
|
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
|
139
|
-
retry
|
146
|
+
sleep(retry_wait_time) && retry
|
140
147
|
end
|
148
|
+
exit 42
|
141
149
|
end
|
data/lib/netsoul/version.rb
CHANGED