• R/O
  • HTTP
  • SSH
  • HTTPS

shogi-server: コミット

shogi-server source


コミットメタ情報

リビジョン44b5f4c6fde18d0ffffb4dbb4cefe6a52ff550ef (tree)
日時2018-08-26 11:57:37
作者Daigo Moriwaki <daigo@debi...>
コミッターDaigo Moriwaki

ログメッセージ

Terminate threads of players so that the server shuts down (Closes #38544)

変更サマリ

差分

--- a/shogi-server
+++ b/shogi-server
@@ -35,6 +35,7 @@ require 'shogi_server/config'
3535 require 'shogi_server/util'
3636 require 'shogi_server/league/floodgate_thread.rb'
3737 require 'pathname'
38+require 'set'
3839 require 'tempfile'
3940
4041 #################################################
@@ -435,6 +436,9 @@ def main
435436
436437 $league.dir = $topdir
437438
439+ # Set of connected players
440+ $players = Set.new
441+
438442 config = {}
439443 config[:BindAddress] = "0.0.0.0"
440444 config[:Port] = port
@@ -462,8 +466,9 @@ def main
462466
463467 srand
464468 server = WEBrick::GenericServer.new(config)
465- ["INT", "TERM"].each do |signal|
469+ ["INT", "TERM"].each do |signal|
466470 trap(signal) do
471+ $players.each {|p| p.kill}
467472 server.shutdown
468473 setup_floodgate.kill
469474 end
@@ -495,6 +500,14 @@ def main
495500 log_message(sprintf("user %s login", player.name))
496501 login.process
497502 player.setup_logger($options["player-log-dir"]) if $options["player-log-dir"]
503+
504+ $mutex.lock
505+ begin
506+ $players.add(player)
507+ ensure
508+ $mutex.unlock
509+ end
510+
498511 player.run(login.csa_1st_str) # loop
499512 $mutex.lock
500513 begin
@@ -504,6 +517,7 @@ def main
504517 player.finish
505518 $league.delete(player)
506519 log_message(sprintf("user %s logout", player.name))
520+ $players.delete(player)
507521 ensure
508522 $mutex.unlock
509523 end
旧リポジトリブラウザで表示