OSDN Git Service

Merge branch 'master' of git.sourceforge.jp:/gitroot/shogi-server/shogi-server
[shogi-server/shogi-server.git] / shogi-server
index 750fa6a..d79f165 100755 (executable)
@@ -1,4 +1,4 @@
-#! /usr/bin/env ruby
+#! /usr/bin/ruby1.9.1
 # $Id$
 #
 # Author:: NABEYA Kenichi, Daigo Moriwaki
 # $Id$
 #
 # Author:: NABEYA Kenichi, Daigo Moriwaki
@@ -415,11 +415,15 @@ def main
   log_message("server started [Revision: #{ShogiServer::Revision}]")
 
   server.start do |client|
   log_message("server started [Revision: #{ShogiServer::Revision}]")
 
   server.start do |client|
+    begin
       # client.sync = true # this is already set in WEBrick 
       client.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
         # Keepalive time can be set by /proc/sys/net/ipv4/tcp_keepalive_time
       player, login = login_loop(client) # loop
       # client.sync = true # this is already set in WEBrick 
       client.setsockopt(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
         # Keepalive time can be set by /proc/sys/net/ipv4/tcp_keepalive_time
       player, login = login_loop(client) # loop
-      next unless player
+      unless player
+        log_error("Detected a timed out login attempt")
+        next
+      end
 
       log_message(sprintf("user %s login", player.name))
       login.process
 
       log_message(sprintf("user %s login", player.name))
       login.process
@@ -430,12 +434,16 @@ def main
         if (player.game)
           player.game.kill(player)
         end
         if (player.game)
           player.game.kill(player)
         end
-        player.finish # socket has been closed
+        player.finish
         $league.delete(player)
         log_message(sprintf("user %s logout", player.name))
       ensure
         $mutex.unlock
       end
         $league.delete(player)
         log_message(sprintf("user %s logout", player.name))
       ensure
         $mutex.unlock
       end
+      player.wait_write_thread_finish(1000) # milliseconds
+    rescue Exception => ex
+      log_error("server.start: #{ex.class}: #{ex.message}\n\t#{ex.backtrace[0]}")
+    end
   end
 end
 
   end
 end