dango 0.4.5 → 0.4.6

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.
@@ -72,10 +72,12 @@ class DangoServerFramework
72
72
 
73
73
  def exit_process() # プロセス終了処理
74
74
  debug_print("shutdown")
75
- begin
76
- # File.delete(@pid_file)
77
- rescue
78
- # puts "failed delete file. #{@pid_file}:#{$!.class}:#{$!.message}"
75
+ if @is_pid_file_create
76
+ begin
77
+ File.delete(@pid_file)
78
+ rescue
79
+ puts "failed delete file. #{@pid_file}:#{$!.class}:#{$!.message}"
80
+ end
79
81
  end
80
82
  puts "shutdown"
81
83
  exit!
@@ -87,6 +89,8 @@ class DangoServerFramework
87
89
  @gserver = nil # Gserver用の変数
88
90
  @server_reload = nil # サーバーのリロード用フラグ
89
91
 
92
+ @is_pid_file_create = nil # pidファイルを作ったかどうかのフラグ
93
+
90
94
  # SIGINT の捕捉
91
95
  Signal.trap(:INT) do
92
96
  logger.warn "SIGINT\n#{caller(0).pretty_inspect}"
@@ -183,6 +187,7 @@ class DangoServerFramework
183
187
 
184
188
  GC.disable
185
189
  open(@pid_file, "wb"){|fh| fh.write Process.pid.to_s } # pidをファイルに保存
190
+ @is_pid_file_create = true # pidファイルを作ったことを記録
186
191
 
187
192
  # @gserver.start(@server_max_connections)
188
193
  @gserver.start(@server_max_connections, 20) # backlogを20に設定
@@ -286,9 +291,9 @@ class DangoServerFramework
286
291
  sock.binmode
287
292
  sock.sync = true
288
293
 
289
- session[:peer_addr] = sock.peeraddr
294
+ session[:peer_addr] = sock.peeraddr
290
295
  session[:peer_ip_address] = sock.peeraddr[3]
291
- session[:peer_host] = sock.peeraddr[2]
296
+ session[:peer_host] = sock.peeraddr[2]
292
297
  end
293
298
 
294
299
  session[:encode_type] = DefaultEncodeType
@@ -306,6 +311,8 @@ class DangoServerFramework
306
311
  @arr_send_response.delete_if{|r| r[:time] < Time.now - 60}
307
312
  end
308
313
 
314
+ logger.debug "thread_main:do main loop."
315
+
309
316
  # メインループ入り
310
317
  loop do
311
318
  if sock.closed?
@@ -322,9 +329,8 @@ class DangoServerFramework
322
329
  end
323
330
 
324
331
  if is_flash_policy_file # Flashのポリシーファイルが来たら
325
- @mutex_sock[sock.object_id].synchronize do
326
- do_flash_policy_file(sid, sock)
327
- end
332
+ logger.debug "is_flash_policy_file"
333
+ do_flash_policy_file(sid, sock)
328
334
 
329
335
  # この部分はポリシーファイルを返す設定に関係なく実行する部分
330
336
  sleep 0.1
@@ -421,36 +427,40 @@ class DangoServerFramework
421
427
  logger.error "Exception #{sid} #{error_message($!, 'u')}"
422
428
 
423
429
  ensure
430
+ # 接続切断の処理
424
431
 
425
- @mutex_proc_thread.synchronize do
426
- begin
427
- if !is_flash_policy_file # Flash Policy Fileなら切断処理不要
428
- logger.info "#{sock.inspect} #{sid} is closing"
429
- if session[:connected] # dango_connect()が実行済みなら
430
- dango_close() # 接続解除時に呼び出されるメソッド
431
- end
432
- end
433
- rescue Exception
434
- logger.error "#{sock.inspect} #{sid} ERROR\n#{error_message($!, 'u')}"
435
- ensure
436
- socket_list.delete(sid) # ソケットリストから削除
432
+ if !is_flash_policy_file # Flash Policy Fileなら切断処理不要
433
+ logger.info "#{sock.inspect} #{sid} is closing"
434
+ if session[:connected] # dango_connect()が実行済みなら
437
435
  begin
438
- @mutex_sock[sock.object_id].synchronize do
439
- sock.close # ソケットを閉じる
440
- end
441
- rescue IOError
442
- logger.info "IOError #{sock.inspect} #{sid}"
436
+ @mutex_proc_thread.synchronize do
437
+ dango_close() # 接続解除時に呼び出されるメソッド
438
+ end # mutex_proc_thread
443
439
  rescue Exception
444
- logger.error "#{sock.inspect} #{sid} Exception\n#{error_message($!, 'u')}"
445
- end
446
-
447
- logger.info "#{sock.inspect} #{sid} is closed"
448
- @mutex_sock[sock.object_id].synchronize do
449
- sock = nil
440
+ logger.error "#{sock.inspect} #{sid} ERROR\n#{error_message($!, 'u')}"
450
441
  end
451
- @mutex_sock.delete(sock.object_id)
452
442
  end
453
- end # mutex_proc_thread
443
+ end
444
+
445
+ begin
446
+ @mutex_sock[sock.object_id].synchronize do
447
+ sock.close # ソケットを閉じる
448
+ end
449
+ rescue IOError
450
+ logger.info "IOError #{sock.inspect} #{sid}"
451
+ rescue Exception
452
+ logger.error "#{sock.inspect} #{sid} Exception\n#{error_message($!, 'u')}"
453
+ end
454
+
455
+ logger.info "#{sock.inspect} #{sid} is closed"
456
+
457
+ socket_list.delete(sid) # ソケットリストから削除
458
+
459
+ @mutex_sock[sock.object_id].synchronize do
460
+ sock = nil # ソケット削除
461
+ end
462
+
463
+ @mutex_sock.delete(sock.object_id) # ソケット排他処理から削除
454
464
 
455
465
  @session_manager.close_session(sid) # sessionの終了処理
456
466
  end
@@ -459,11 +469,10 @@ class DangoServerFramework
459
469
 
460
470
  # Flashのポリシーファイルの処理
461
471
  def do_flash_policy_file(sid, sock)
462
- logger.debug "is_flash_policy_file"
463
472
 
464
473
  if @policy_file_request # ポリシーファイルを返す設定なら
465
474
  logger.info "is_flash_policy_file #{sid} #{@policy_file_request}"
466
-
475
+
467
476
  allow_str = ""
468
477
 
469
478
  @policy_file_allow_domain.each do |one_host|
@@ -479,8 +488,11 @@ class DangoServerFramework
479
488
  EOF
480
489
 
481
490
  logger.debug policy_data
482
- sock.write policy_data
483
- sock.flush
491
+ @mutex_sock[sock.object_id].synchronize do
492
+ sock.write policy_data
493
+ sock.flush
494
+ end
495
+
484
496
  logger.info "policy file sent."
485
497
  end
486
498
  end
@@ -636,14 +648,14 @@ EOF
636
648
  begin
637
649
  sleep @gc_interval_sec
638
650
 
639
- # Thread.critical = true
640
- logger.debug "GC start "
641
- gc_start_time = Time.now
642
- GC.enable
643
- GC.start
644
- GC.disable
645
- logger.debug "GC end #{Time.now - gc_start_time}sec "
646
- # Thread.critical = false
651
+ @mutex_proc_thread.synchronize do
652
+ logger.debug "GC start "
653
+ gc_start_time = Time.now
654
+ GC.enable
655
+ GC.start
656
+ GC.disable
657
+ logger.debug "GC end #{Time.now - gc_start_time}sec "
658
+ end
647
659
 
648
660
  output_memory_statistics() if @statistics_process_memory # メモリ使用量統計
649
661
 
@@ -11,8 +11,8 @@ module DangoFrameworkModule
11
11
  def initialize(config)
12
12
  @config = config
13
13
  @data = {}
14
- # @mutex = {}
15
- @mutex = Mutex.new
14
+ @mutex = {}
15
+ # @mutex = Mutex.new
16
16
 
17
17
  @transact_key = {}
18
18
  @transact_thread = {}
@@ -66,8 +66,8 @@ module DangoFrameworkModule
66
66
  raise(DangoFrameworkException, "Shared key is not exist.")
67
67
  end
68
68
 
69
- # @mutex[key].synchronize do
70
- @mutex.synchronize do
69
+ @mutex[key].synchronize do
70
+ # @mutex.synchronize do
71
71
  @transact_key[Thread.current] = key # 違うスレッドからcommitできないように
72
72
 
73
73
  raise("nested transaction #{key}") if @transact_thread.has_key?(key)
@@ -148,8 +148,8 @@ module DangoFrameworkModule
148
148
  # raise(DangoFrameworkException, "Shared key is not exist.")
149
149
  end
150
150
 
151
- # @mutex[key].synchronize do
152
- @mutex.synchronize do
151
+ @mutex[key].synchronize do
152
+ # @mutex.synchronize do
153
153
  @data[key].deep_dup
154
154
  end
155
155
  end
@@ -164,13 +164,13 @@ module DangoFrameworkModule
164
164
  key = key.to_s
165
165
 
166
166
  # 未定義なら定義する
167
- # if !@data.has_key?(key)
168
- # @mutex[key] = Mutex.new
169
- # end
167
+ if !@data.has_key?(key)
168
+ @mutex[key] = Mutex.new
169
+ end
170
170
 
171
171
  # ロックしてデータを入れる
172
- # @mutex[key].synchronize do
173
- @mutex.synchronize do
172
+ @mutex[key].synchronize do
173
+ # @mutex.synchronize do
174
174
  @data[key] = value.deep_dup
175
175
  end
176
176
 
@@ -2,7 +2,7 @@ module Dango #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dango
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keisuke Minami
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - "="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.5
33
+ version: 0.4.6
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: hoe