dango 0.0.10 → 0.0.11
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.
- data/lib/dango/client_framework.rb +28 -15
- data/lib/dango/framework_base.rb +12 -9
- data/lib/dango/server_framework.rb +21 -8
- data/lib/dango/tester/dango_tester_client.rb +13 -12
- data/lib/dango/version.rb +1 -1
- metadata +2 -2
@@ -60,7 +60,7 @@ class DangoClientFramework
|
|
60
60
|
@log_level = @connection_client_log_level
|
61
61
|
|
62
62
|
# loggerの準備
|
63
|
-
cs_logger.debug("client initialize")
|
63
|
+
cs_logger.debug("-------client initialize")
|
64
64
|
|
65
65
|
# データ送受信用の共有メモリ初期化
|
66
66
|
send_receive_shared_init()
|
@@ -84,53 +84,59 @@ class DangoClientFramework
|
|
84
84
|
@tmutex = Mutex.new # sockの排他処理用
|
85
85
|
cs_logger.debug("addr:#{@sock.addr.inspect}")
|
86
86
|
|
87
|
+
@sid = nil # 接続して決まるsidを保持
|
88
|
+
|
87
89
|
# データ受信用のスレッドの開始
|
88
90
|
@thread_receive = Thread.start{ thread_main() }
|
89
91
|
end
|
90
92
|
|
93
|
+
attr_reader(:sid)
|
94
|
+
|
91
95
|
# データ受信用のスレッド処理
|
92
96
|
def thread_main()
|
93
97
|
catch(:session_closed) do
|
94
98
|
loop do
|
95
99
|
begin
|
96
100
|
if @sock
|
97
|
-
cs_logger.debug "start receive_data"
|
101
|
+
cs_logger.debug "#{@sid}:start receive_data"
|
98
102
|
ret_obj = nil
|
99
103
|
begin
|
100
104
|
ret_obj = cs_receive_data(@sock) # データ受信処理
|
101
105
|
rescue DangoFrameworkConnectionError
|
102
|
-
cs_logger.debug "sock error:#{error_message($!, 'u')}"
|
106
|
+
cs_logger.debug "#{@sid}:sock error:#{error_message($!, 'u')}"
|
103
107
|
throw(:session_closed)
|
104
108
|
rescue DangoFrameworkError
|
105
|
-
cs_logger.debug "sock error:#{error_message($!, 'u')}"
|
109
|
+
cs_logger.debug "#{@sid}:sock error:#{error_message($!, 'u')}"
|
106
110
|
throw(:session_closed)
|
107
111
|
end
|
108
|
-
cs_logger.debug "finished cs_receive_data:#{ret_obj.inspect}"
|
112
|
+
cs_logger.debug "#{@sid}:finished cs_receive_data:#{ret_obj.inspect}"
|
109
113
|
|
110
114
|
if !(ret_obj && ret_obj["notice"])
|
111
|
-
cs_logger.info "no notice:#{ret_obj["notice"].inspect}"
|
115
|
+
cs_logger.info "#{@sid}:no notice:#{ret_obj["notice"].inspect}"
|
112
116
|
end
|
113
117
|
|
114
118
|
# メソッド呼び出し
|
115
|
-
cs_logger.info "calling method=#{ret_obj["notice"].inspect}"
|
119
|
+
cs_logger.info "#{@sid}:calling method=#{ret_obj["notice"].inspect}"
|
116
120
|
begin
|
117
121
|
__send__("cs_receive_#{ret_obj["notice"]}", ret_obj)
|
118
122
|
rescue
|
119
123
|
cs_logger.error "error in cs_receive_#{ret_obj["notice"]}\n#{error_message($!, 'u')}"
|
124
|
+
ensure
|
125
|
+
# データの受信の送信返し
|
126
|
+
response_notice_name = "_response"
|
127
|
+
send_obj = {"_id" => ret_obj["_id"]}
|
128
|
+
cs_client_send_data(response_notice_name, send_obj)
|
129
|
+
cs_logger.debug "#{@sid}:response_notice_name=#{response_notice_name.inspect}"
|
120
130
|
end
|
121
|
-
cs_logger.debug "called method=#{ret_obj["notice"].inspect}"
|
131
|
+
cs_logger.debug "#{@sid}:called method=#{ret_obj["notice"].inspect}"
|
122
132
|
|
123
|
-
# データの受信の送信返し
|
124
|
-
response_notice_name = "_response"
|
125
|
-
send_obj = {"_id" => ret_obj["_id"]}
|
126
|
-
cs_client_send_data(response_notice_name, send_obj)
|
127
133
|
|
128
134
|
else
|
129
135
|
sleep 0.1
|
130
136
|
end
|
131
137
|
|
132
138
|
rescue Exception
|
133
|
-
cs_logger.debug "#{error_message($!, 'u')}"
|
139
|
+
cs_logger.debug "#{@sid}:#{error_message($!, 'u')}"
|
134
140
|
end
|
135
141
|
end
|
136
142
|
end
|
@@ -139,6 +145,11 @@ class DangoClientFramework
|
|
139
145
|
end
|
140
146
|
private :thread_main
|
141
147
|
|
148
|
+
# 接続直後のsid通知なら
|
149
|
+
def cs_receive__notice_sid(rec_obj)
|
150
|
+
@sid = rec_obj["_sid"]
|
151
|
+
end
|
152
|
+
|
142
153
|
# ユーザーが終了させたい時に呼び出すメソッド(セッションを切る)
|
143
154
|
def cs_client_close
|
144
155
|
client_quit() # クライアントの終了処理
|
@@ -177,6 +188,7 @@ class DangoClientFramework
|
|
177
188
|
|
178
189
|
# クライアントからサーバーへのデータ送信
|
179
190
|
def cs_client_send_data(action_name, send_obj)
|
191
|
+
cs_logger.debug "cs_client_send_data(#{action_name.inspect}, #{send_obj['_id']}) #{Time.now}"
|
180
192
|
send_obj_dup = send_obj.dup
|
181
193
|
send_obj_dup["action"] = action_name.to_s
|
182
194
|
cs_send_data(@sock, send_obj_dup)
|
@@ -188,7 +200,8 @@ class DangoClientFramework
|
|
188
200
|
# return_nameは省略時は、action_nameの頭にreturnを付けたもののシンボルになる
|
189
201
|
# timeoutは省略時は6秒
|
190
202
|
def cs_client_send_receive_data(action_name, send_obj, options = {})
|
191
|
-
cs_logger.debug "cs_client_send_receive_data(#{action_name.inspect}
|
203
|
+
# cs_logger.debug "cs_client_send_receive_data(#{action_name.inspect})"
|
204
|
+
# cs_logger.debug "cs_client_send_receive_data(#{action_name.inspect}, #{send_obj.inspect}, #{options.inspect})"
|
192
205
|
|
193
206
|
return_name = options[:return_name] || ("return_" + action_name.to_s).to_sym
|
194
207
|
timeout = options[:timeout] || 6
|
@@ -204,7 +217,7 @@ class DangoClientFramework
|
|
204
217
|
instance_method_name = "cs_receive_#{return_name}"
|
205
218
|
expr = <<-EOF
|
206
219
|
def self.#{instance_method_name}(ret_obj)
|
207
|
-
cs_logger.debug "ret_obj:" + ret_obj.inspect
|
220
|
+
# cs_logger.debug "ret_obj:" + ret_obj.inspect
|
208
221
|
send_receive_shared[#{action_name_sym}] = ret_obj
|
209
222
|
end
|
210
223
|
EOF
|
data/lib/dango/framework_base.rb
CHANGED
@@ -40,16 +40,17 @@ class Object
|
|
40
40
|
end
|
41
41
|
|
42
42
|
# Timeクラスの表示形式修正
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
class Time
|
44
|
+
def to_s
|
45
|
+
self.strftime("%Y-%m-%d %H:%M:%S")
|
46
|
+
end
|
47
|
+
end
|
48
48
|
|
49
49
|
# 例外定義
|
50
50
|
class DangoFrameworkError < StandardError; end
|
51
51
|
class DangoFrameworkTimeoutError < DangoFrameworkError; end
|
52
52
|
class DangoFrameworkConnectionError < DangoFrameworkError; end
|
53
|
+
class DangoFrameworkReadNoDataError < DangoFrameworkError; end
|
53
54
|
class DangoFrameworkFlashPolicyError < DangoFrameworkError; end
|
54
55
|
|
55
56
|
# エラー出力用モジュール
|
@@ -76,7 +77,7 @@ module DangoUtilModule
|
|
76
77
|
# arrは順番を入れ替えたい配列
|
77
78
|
# numは入れ替え回数(省略時2、大きな数を入れると確実にランダムになるが時間が掛かる)
|
78
79
|
def array_random(arr, num = 2)
|
79
|
-
|
80
|
+
arr.sort_by{rand}.deep_dup
|
80
81
|
|
81
82
|
# ret_arr = arr.deep_dup
|
82
83
|
# (ret_arr.size * num).times do # メンバー数のnum倍の回数、入れ替え
|
@@ -142,9 +143,11 @@ module DangoFrameworkModule
|
|
142
143
|
raise(DangoFrameworkConnectionError, "failed to read sock.\n#{error_message($!, 'u')}")
|
143
144
|
end
|
144
145
|
|
146
|
+
raise(DangoFrameworkReadNoDataError, "sid=#{Thread.current.object_id}:size_str=#{size_str.inspect}") if size_str == ""
|
147
|
+
|
145
148
|
dtype, size = size_str[0, 5].unpack("cN")
|
146
149
|
|
147
|
-
raise(DangoFrameworkConnectionError, "size=#{size}:size_str=#{size_str.inspect}") if size == nil || size == 0
|
150
|
+
raise(DangoFrameworkConnectionError, "sid=#{Thread.current.object_id}:size=#{size}:size_str=#{size_str.inspect}") if size == nil || size == 0
|
148
151
|
|
149
152
|
## Flash のpolicyファイルだった場合(特殊)
|
150
153
|
if size == 1886350441
|
@@ -158,7 +161,7 @@ module DangoFrameworkModule
|
|
158
161
|
end
|
159
162
|
end
|
160
163
|
|
161
|
-
cs_logger.debug "size=#{size}:size_str=#{size_str.inspect}"
|
164
|
+
# cs_logger.debug "size=#{size}:size_str=#{size_str.inspect}"
|
162
165
|
|
163
166
|
ret_data_orig = ""
|
164
167
|
|
@@ -179,7 +182,7 @@ module DangoFrameworkModule
|
|
179
182
|
# cs_logger.debug "size:#{size.inspect}"
|
180
183
|
end
|
181
184
|
|
182
|
-
cs_logger.debug "ret_data_orig:#{ret_data_orig.inspect}"
|
185
|
+
# cs_logger.debug "ret_data_orig:#{ret_data_orig.inspect}"
|
183
186
|
|
184
187
|
ret_data = cs_receive_decrypt(ret_data_orig[0..-2])
|
185
188
|
|
@@ -176,14 +176,20 @@ class DangoServerFramework
|
|
176
176
|
|
177
177
|
begin
|
178
178
|
session[:session_id] = Thread.current.object_id
|
179
|
-
|
180
|
-
|
179
|
+
session_id = session[:session_id]
|
180
|
+
socket_list.add(session_id, sock)
|
181
|
+
mutex_socket_list.add(session_id)
|
181
182
|
|
182
183
|
sock.binmode
|
183
184
|
sock.sync = true
|
184
185
|
|
185
186
|
cs_connect() # 接続時メソッド呼び出し
|
186
187
|
|
188
|
+
# 接続直後のsid通知
|
189
|
+
session_id = session_id
|
190
|
+
send_obj = {"_sid"=>session_id}
|
191
|
+
cs_server_send_data(session_id, "_notice_sid", send_obj)
|
192
|
+
|
187
193
|
# メインループ入り
|
188
194
|
loop do
|
189
195
|
if sock.closed?
|
@@ -214,19 +220,23 @@ class DangoServerFramework
|
|
214
220
|
|
215
221
|
# アクション名
|
216
222
|
action_name = ret_obj["action"].to_s
|
217
|
-
cs_logger.debug "action_name=#{action_name}"
|
218
223
|
|
219
224
|
@mutex_proc_thread.synchronize do
|
220
225
|
|
221
226
|
if action_name == '_response' # 送信パケットの返事なら
|
227
|
+
# cs_logger.debug "action_name=#{action_name} #{Time.now}"
|
222
228
|
action_name_is_response(ret_obj)
|
229
|
+
|
223
230
|
elsif action_name == 'monitor_all_info' # メンテナンスアクション名なら
|
224
231
|
cs_check_monitor_error(sock, "return_monitor_all_info")
|
225
232
|
cs_server_monitor_all_info()
|
233
|
+
|
226
234
|
elsif action_name == 'monitor_server_reload' # メンテナンスアクション名なら
|
227
235
|
cs_check_monitor_error(sock, "return_monitor_server_reload")
|
228
236
|
cs_server_monitor_server_reload()
|
237
|
+
|
229
238
|
else # メンテナンスコマンド以外のユーザーアクション名なら
|
239
|
+
cs_logger.debug "action_name=#{action_name} #{Time.now}"
|
230
240
|
begin
|
231
241
|
__send__("cs_receive_#{action_name}", ret_obj)
|
232
242
|
rescue NoMethodError
|
@@ -239,18 +249,21 @@ class DangoServerFramework
|
|
239
249
|
end
|
240
250
|
end
|
241
251
|
|
252
|
+
rescue DangoFrameworkReadNoDataError
|
253
|
+
cs_logger.debug "read no data. maybe client closed. #{Thread.current.object_id} #{Time.now}"
|
254
|
+
|
242
255
|
rescue DangoFrameworkConnectionError
|
243
256
|
@recv_fail_count += 1 if @recv_fail_count # 受信失敗回数カウント
|
244
|
-
cs_logger.debug "connection error. \n#{error_message($!, 'u')}"
|
257
|
+
cs_logger.debug "connection error. #{Thread.current.object_id} #{Time.now}\n#{error_message($!, 'u')}"
|
245
258
|
|
246
259
|
rescue DangoFrameworkError
|
247
|
-
cs_logger.debug "DangoFrameworkError. \n#{error_message($!, 'u')}"
|
260
|
+
cs_logger.debug "DangoFrameworkError. #{Thread.current.object_id} #{Time.now}\n#{error_message($!, 'u')}"
|
248
261
|
|
249
262
|
rescue Exception
|
250
|
-
cs_logger.error "#{error_message($!, 'u')}"
|
263
|
+
cs_logger.error "Exception #{Thread.current.object_id} #{Time.now} #{error_message($!, 'u')}"
|
251
264
|
|
252
265
|
ensure
|
253
|
-
cs_logger.debug "#{sock.inspect} is gone"
|
266
|
+
cs_logger.debug "#{sock.inspect} #{Thread.current.object_id} is gone"
|
254
267
|
|
255
268
|
@mutex_proc_thread.synchronize do
|
256
269
|
begin
|
@@ -261,7 +274,7 @@ class DangoServerFramework
|
|
261
274
|
socket_list.delete(Thread.current.object_id) # ソケットリストから削除
|
262
275
|
sock.close # ソケットを閉じる
|
263
276
|
|
264
|
-
cs_logger.debug "#{sock.inspect} is gone 2"
|
277
|
+
cs_logger.debug "#{sock.inspect} #{Thread.current.object_id} is gone 2"
|
265
278
|
end
|
266
279
|
end
|
267
280
|
|
@@ -5,12 +5,14 @@
|
|
5
5
|
=end
|
6
6
|
|
7
7
|
require 'dango/client_framework' # コネクションクライアントフレームワークの呼び出し
|
8
|
+
require 'thread'
|
8
9
|
|
9
10
|
# テスタークラス
|
10
11
|
class DangoTesterClient
|
11
12
|
# テスターのイニシャライズ
|
12
13
|
def initialize
|
13
14
|
@client_conns = {}
|
15
|
+
Thread.abort_on_exception = true
|
14
16
|
end
|
15
17
|
|
16
18
|
# クライアントを1個接続
|
@@ -24,7 +26,7 @@ class DangoTesterClient
|
|
24
26
|
env = "development"
|
25
27
|
|
26
28
|
# 接続
|
27
|
-
client_conn = TestClient.new(env, config)
|
29
|
+
client_conn = TestClient.new(env, config, c_name)
|
28
30
|
|
29
31
|
# client_nameメソッド作成とclient_nameを定義
|
30
32
|
client_conn.client_name = c_name
|
@@ -42,17 +44,16 @@ end
|
|
42
44
|
# テスト接続用のクラス
|
43
45
|
class TestClient < DangoClientFramework
|
44
46
|
SendReceiveSleepIntervalSec = 0.1 # データ送信後の順の際のタイムアウトチェック間隔秒
|
45
|
-
SendReceiveTimeoutSec =
|
47
|
+
SendReceiveTimeoutSec = 10 # データ送信後の順の際のタイムアウトチェック間隔秒
|
46
48
|
|
47
|
-
def initialize(env, config)
|
49
|
+
def initialize(env, config, c_name)
|
48
50
|
@config = config
|
51
|
+
@client_name = c_name # クライアント名
|
52
|
+
|
49
53
|
super(env, config)
|
50
54
|
|
51
55
|
@receive_mutex = Mutex.new # 送受信用の排他処理
|
52
56
|
@receive_arr = []
|
53
|
-
@receive_defined_names = []
|
54
|
-
|
55
|
-
@client_name = nil # クライアント名
|
56
57
|
|
57
58
|
send_receive_shared_init()
|
58
59
|
end
|
@@ -72,7 +73,7 @@ class TestClient < DangoClientFramework
|
|
72
73
|
@connection_client_port = @config["network"]["port"] # 自動でこのポートでサーバー開始
|
73
74
|
|
74
75
|
# ログ出力情報
|
75
|
-
@connection_client_log_file = "log/
|
76
|
+
@connection_client_log_file = "log/tester_#{@client_name}.log" # 自動でこのログファイル名を使う
|
76
77
|
@connection_client_log_level = Logger::DEBUG # 自動でこのログレベルになる
|
77
78
|
end
|
78
79
|
|
@@ -82,12 +83,11 @@ class TestClient < DangoClientFramework
|
|
82
83
|
cs_client_send_data(name, send_obj)
|
83
84
|
end
|
84
85
|
|
85
|
-
#
|
86
|
-
def
|
86
|
+
# trap_receive_data
|
87
|
+
def trap_receive_data(receive_name, options = {})
|
88
|
+
cs_logger.debug "trap_receive_data:#{receive_name}:#{Time.now}"
|
87
89
|
timeout = options[:timeout] || SendReceiveTimeoutSec
|
88
90
|
|
89
|
-
@receive_defined_names.push(receive_name)
|
90
|
-
|
91
91
|
Thread.start do
|
92
92
|
send_receive_shared[receive_name] = nil
|
93
93
|
end_reserved_time = Time.now + timeout
|
@@ -119,10 +119,11 @@ class TestClient < DangoClientFramework
|
|
119
119
|
end
|
120
120
|
|
121
121
|
if !send_receive_shared[receive_name] # 戻ってきたデータがあるかどうかチェック
|
122
|
-
raise(DangoFrameworkError, "received data is none")
|
122
|
+
raise(DangoFrameworkError, "received data is none. sid=#{sid} receive_name=#{receive_name}")
|
123
123
|
end
|
124
124
|
|
125
125
|
@receive_mutex.synchronize do
|
126
|
+
cs_logger.debug "receive_name:#{receive_name}:#{send_receive_shared[receive_name].inspect}"
|
126
127
|
@receive_arr.push([receive_name, send_receive_shared[receive_name]])
|
127
128
|
# p @receive_arr
|
128
129
|
end
|
data/lib/dango/version.rb
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: dango
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-10-
|
6
|
+
version: 0.0.11
|
7
|
+
date: 2007-10-16 00:00:00 +09:00
|
8
8
|
summary: Ruby - Flash conneciton network flamework
|
9
9
|
require_paths:
|
10
10
|
- lib
|