From: Steinar H. Gunderson Date: Sat, 7 Jul 2007 18:27:04 +0000 (+0200) Subject: Change to unbuffered reading for the UCI channel. X-Git-Url: https://git.sesse.net/?p=remoteglot;a=commitdiff_plain;h=d3db57677e015c6e3371df0acb7549447a9db771 Change to unbuffered reading for the UCI channel. --- diff --git a/remoteglot.pl b/remoteglot.pl index 28bebd2..6b423f6 100755 --- a/remoteglot.pl +++ b/remoteglot.pl @@ -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 = ; + # + # 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;