OSDN Git Service

- shogi_server/command.rb: Fixed an issue that MONITOR2OFF did not
[shogi-server/shogi-server.git] / shogi_server / player.rb
index 02b75f3..fedbba7 100644 (file)
@@ -192,6 +192,7 @@ class Player < BasicPlayer
         log_debug("Terminating %s's write thread..." % [@name])
         if @write_thread && @write_thread.alive?
           write_safe(nil)
+          Thread.pass # help the write_thread to terminate
         end
         @player_logger.close if @player_logger
         log_debug("done.")
@@ -258,6 +259,7 @@ class Player < BasicPlayer
   def run(csa_1st_str=nil)
     while ( csa_1st_str || 
             str = gets_safe(@socket, (@socket_buffer.empty? ? Default_Timeout : 1)) )
+      time = Time.now
       log(:info, :in, str) if str && str.instance_of?(String) 
       $mutex.lock
       begin
@@ -281,7 +283,11 @@ class Player < BasicPlayer
         end
         str.chomp! if (str.class == String) # may be strip! ?
 
-        cmd = ShogiServer::Command.factory(str, self)
+        delay = Time.now - time
+        if delay > 5
+          log_warning("Detected a long delay: %.2f sec" % [delay])
+        end
+        cmd = ShogiServer::Command.factory(str, self, time)
         case cmd.call
         when :return
           return
@@ -295,6 +301,7 @@ class Player < BasicPlayer
         $mutex.unlock
       end
     end # enf of while
+    log_warning("%s's socket was suddenly closed" % [@name])
   end # def run
 end # class