OSDN Git Service

Merge branch 'wdoor-stable'
[shogi-server/shogi-server.git] / test / baseclient.rb
index f45dc44..f6d7487 100644 (file)
@@ -35,21 +35,25 @@ class SocketPlayer
 
   def reader
     @thread = Thread.new do
-      Thread.pass
-      loop do 
-#        break if @socket.closed?
-        if r = select([@socket], nil, nil, 10)
-          str = r[0].first.gets
-          break if str.nil?
-          @mutex.synchronize do
-            if %r!^[\+\-]\d{4}\w{2},T\d+$! =~ str
-                @received_moves += 1
+      begin
+        Thread.pass
+        loop do 
+          break if @socket.closed?
+          if r = select([@socket], nil, nil, 10)
+            str = r[0].first.gets
+            break if str.nil?
+            @mutex.synchronize do
+              if %r!^[\+\-]\d{4}\w{2},T\d+$! =~ str
+                  @received_moves += 1
+              end
+              @message << str
             end
-            @message << str
+          else
+            raise "timed out"
           end
-        else
-          raise "timed out"
         end
+      rescue IOError
+        $stderr.puts "\nReader thread interrupted"
       end
     end
   end
@@ -123,8 +127,8 @@ class SocketPlayer
   end
 
   def logout
-    stop_reader
     @socket.puts "LOGOUT"
+    @socket.close
   end
 
 end
@@ -186,7 +190,7 @@ class BaseClient < Test::Unit::TestCase
     @p1.login
     sleep 0.1
     @p2.login
-    sleep 0.1
+    sleep 0.5
     @p1.game
     sleep 0.1
     @p2.game