shogi-server source
Revisão | 360533de4731f88c6e4e5b4a3ff1979e6fb1b07e (tree) |
---|---|
Hora | 2020-12-14 20:42:55 |
Autor | Mizar <mizar.jp@gmai...> |
Commiter | Mizar |
work for Windows wip
@@ -28,6 +28,7 @@ $:.unshift(File.join(File.dirname(File.expand_path(__FILE__)), "..")) | ||
28 | 28 | require 'shogi_server' |
29 | 29 | require 'logger' |
30 | 30 | require 'socket' |
31 | +require 'timeout' | |
31 | 32 | |
32 | 33 | # Global variables |
33 | 34 |
@@ -482,7 +483,14 @@ class BridgeState | ||
482 | 483 | throw "Bad state at event_engine_recv: #@state" |
483 | 484 | end |
484 | 485 | |
485 | - str = $server.gets | |
486 | + str = nil | |
487 | + begin | |
488 | + Timeout.timeout(0.001){ | |
489 | + str = $server.gets | |
490 | + } | |
491 | + rescue Timeout::Error | |
492 | + log_error "event_server_recv timeout" | |
493 | + end | |
486 | 494 | return if str.nil? || str.strip.empty? |
487 | 495 | log_server_recv str |
488 | 496 |
@@ -598,9 +606,15 @@ end | ||
598 | 606 | def start_engine |
599 | 607 | log_info("Starting engine... #{$options[:engine_path]}") |
600 | 608 | |
601 | - cmd = %Q!| #{$options[:engine_path]}! | |
602 | - $engine = open(cmd, "w+") | |
609 | + $engine = IO.popen($options[:engine_path], "w+") | |
603 | 610 | $engine.sync = true |
611 | + if false and RUBY_PLATFORM.downcase =~ /mswin|mingw|cygwin|bccwin|msys/ | |
612 | + require 'Win32API' | |
613 | + get_osfhandle = Win32API.new('msvcrt', '_get_osfhandle', 'I', 'L') | |
614 | + set_namedpipehandlestate = Win32API.new('kernel32', 'SetNamedPipeHandleState', 'LPPP', 'I') | |
615 | + os_fhandle = get_osfhandle.call($engine.to_i) | |
616 | + pipe_res = set_namedpipehandlestate.call(os_fhandle, [1].pack("L"), [0].pack("L"), [0].pack("L")) | |
617 | + end | |
604 | 618 | |
605 | 619 | select(nil, [$engine], nil) |
606 | 620 | log_engine_send "usi" |