DroidFish: Rewrote the engine communication so that the GUI never waits for the engine.

This commit is contained in:
Peter Osterlund
2011-12-31 02:30:18 +00:00
parent 9d7d30b293
commit c1ab57b4f9
10 changed files with 959 additions and 715 deletions

View File

@@ -73,20 +73,26 @@ static std::deque<char> inBuf;
static bool getNextChar(int& c, int timeoutMillis) {
if (inBuf.empty()) {
fd_set readfds, writefds;
fd_set readfds, exceptfds;
FD_ZERO(&readfds);
FD_SET(fdFromChild, &readfds);
FD_ZERO(&exceptfds);
FD_SET(fdFromChild, &exceptfds);
struct timeval tv;
tv.tv_sec = timeoutMillis / 1000;
tv.tv_usec = (timeoutMillis % 1000) * 1000;
int ret = select(fdFromChild + 1, &readfds, NULL, NULL, &tv);
if (ret < 0)
int ret = select(fdFromChild + 1, &readfds, NULL, &exceptfds, &tv);
if ((ret < 0) || FD_ISSET(fdFromChild, &exceptfds))
return false;
static char buf[4096];
int len = read(fdFromChild, &buf[0], sizeof(buf));
for (int i = 0; i < len; i++)
inBuf.push_back(buf[i]);
if (FD_ISSET(fdFromChild, &readfds)) {
static char buf[4096];
int len = read(fdFromChild, &buf[0], sizeof(buf));
if (len == 0)
return false; // EOF
for (int i = 0; i < len; i++)
inBuf.push_back(buf[i]);
}
}
if (inBuf.empty()) {
c = -1;