From: Yann Dirson Date: Mon, 14 Oct 2013 19:38:24 +0000 (+0200) Subject: Regularly check for user input when searching, to have a chance to catch EOF from... X-Git-Url: http://winboard.nl/cgi-bin?p=gnushogi.git;a=commitdiff_plain;h=74ba6a1c63855ebd51dbe316582a16e7ca95c0a4 Regularly check for user input when searching, to have a chance to catch EOF from engine. When an engine quits without terminating a searching gnushogi, it would continue to search and never realize there was no reason to continue. This is a poll-based implementation of what H.G.Muller wrote for WIN32 to circumvent the lack of UNIX signals there. --- diff --git a/gnushogi/search.c b/gnushogi/search.c index 2cfff17..1491057 100644 --- a/gnushogi/search.c +++ b/gnushogi/search.c @@ -30,6 +30,8 @@ */ #include "gnushogi.h" +#include +#include #if !defined OLDTIME && defined HAVE_GETTIMEOFDAY double pow(double x, double y); @@ -176,6 +178,7 @@ SelectMove(short side, SelectMove_mode iop) } else { + background = false; /* [HGM] with ponder on we did not switch back to foreground mode??? */ player = side; SetResponseTime(side); } @@ -529,6 +532,8 @@ search(short side, short best = -(SCORE_LIMIT + 3000); short bestwidth = 0; short mustcut; + static struct pollfd pollfds[1] = { /* [0] = */ { /* .fd = */ STDIN_FILENO, + /* .events = */ POLLIN } }; #ifdef NULLMOVE short PVsave; @@ -546,6 +551,19 @@ search(short side, { ElapsedTime(COMPUTE_MODE); + if(background) { + int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0); + if (cnt < 0) { + perror("polling standard input"); + ExitShogi(); + } + if (cnt) { /* if anything to read, or error occured */ + if (!flag.timeout) + flag.back = true; /* previous: flag.timeout = true; */ + flag.bothsides = false; + } + } + if (flag.back) { flag.back = false;