]> git.sesse.net Git - remoteglot/commitdiff
Change to unbuffered reading for the UCI channel.
authorSteinar H. Gunderson <sesse@debian.org>
Sat, 7 Jul 2007 18:27:04 +0000 (20:27 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Sat, 7 Jul 2007 18:27:04 +0000 (20:27 +0200)
remoteglot.pl

index 28bebd25cfcf57de6e1685b83b202e9c03ebb70f..6b423f691573fafa8c85761e5e4abc41cb6e0754 100755 (executable)
@@ -23,7 +23,7 @@ my $target = "22";
 my $engine = "wine Rybkav2.3.2a.mp.w32.exe";
 my $telltarget = undef;   # undef to be silent
 my @tell_intervals = (5, 20, 60, 120, 240, 480, 960);  # after each move
-my $uci_assume_full_compliance = 0;                    # dangerous :-)
+my $uci_assume_full_compliance = 1;                    # dangerous :-)
 
 # Program starts here
 $SIG{ALRM} = sub { output_screen(); };
@@ -154,7 +154,27 @@ while (1) {
        
        # any fun on the UCI channel?
        if ($nfound > 0 && vec($rout, fileno(UCIREAD), 1) == 1) {
-               my $line = <UCIREAD>;
+               # 
+               # Read until we've got a full line -- if the engine sends part of
+               # a line and then stops we're pretty much hosed, but that should
+               # never happen.
+               #
+               my $line = '';
+               while ($line !~ /\n/) {
+                       my $tmp;
+                       my $ret = sysread UCIREAD, $tmp, 1;
+
+                       if (!defined($ret)) {
+                               next if ($!{EINTR});
+                               die "error in reading from the UCI engine: $!";
+                       } elsif ($ret == 0) {
+                               die "EOF from UCI engine";
+                       }
+
+                       $line .= $tmp;
+               }
+
+               $line =~ tr/\r\n//d;
                handle_uci($line);
                $sleep = 0;