X-Git-Url: http://winboard.nl/cgi-bin?p=uci2wb.git;a=blobdiff_plain;f=UCI2WB.c;h=00501461cc033a50cec0417b501bf260c418931a;hp=764f9217d85d3db4e59d8885c0c84c51b0a8be53;hb=5d50faa12b64983f87219b8b4a50ce8a6c7bcbee;hpb=35ffc8b7ee8e505a23a9ce60a5734a72560d93a5 diff --git a/UCI2WB.c b/UCI2WB.c index 764f921..0050146 100644 --- a/UCI2WB.c +++ b/UCI2WB.c @@ -20,12 +20,6 @@ #include #include -#ifdef _MSC_VER -#define SLEEP() Sleep(1) -#else -#define SLEEP() usleep(10) -#endif - // Set VARIANTS for in WinBoard variant feature. (With -s option this will always be reset to use "shogi".) # define VARIANTS "normal,xiangqi" @@ -41,6 +35,21 @@ int statDepth, statScore, statNodes, statTime, currNr, size; char currMove[20]; FILE *toE, *fromE; int pid; +#ifdef WIN32 +WinPipe(HANDLE *hRd, HANDLE *hWr) +{ + SECURITY_ATTRIBUTES saAttr; + + /* Set the bInheritHandle flag so pipe handles are inherited. */ + saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); + saAttr.bInheritHandle = TRUE; + saAttr.lpSecurityDescriptor = NULL; + + /* Create a pipe */ + return CreatePipe(hRd, hWr, &saAttr, 0); +} +#endif + #define INIT 0 #define WAKEUP 1 #define PAUSE 2 @@ -49,7 +58,12 @@ void Sync (int action) { #ifdef WIN32 - if(action == PAUSE) while(pause) SLEEP(); // in Windows we still rely on polling. :-( + static HANDLE hWr, hRd; DWORD d; char c; + switch(action) { + case INIT: WinPipe(&hRd, &hWr); break; + case WAKEUP: WriteFile(hWr, "\n", 1, &d, NULL); break; + case PAUSE: ReadFile(hRd, &c, 1, &d, NULL); + } #else static int syncPipe[2]; char c; switch(action) { @@ -342,22 +356,16 @@ StartEngine(char *cmdLine, char *dir) #ifdef WIN32 HANDLE hChildStdinRd, hChildStdinWr, hChildStdoutRd, hChildStdoutWr; - SECURITY_ATTRIBUTES saAttr; BOOL fSuccess; PROCESS_INFORMATION piProcInfo; STARTUPINFO siStartInfo; DWORD err; - /* Set the bInheritHandle flag so pipe handles are inherited. */ - saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); - saAttr.bInheritHandle = TRUE; - saAttr.lpSecurityDescriptor = NULL; - /* Create a pipe for the child's STDOUT. */ - if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) return GetLastError(); + if (! WinPipe(&hChildStdoutRd, &hChildStdoutWr)) return GetLastError(); /* Create a pipe for the child's STDIN. */ - if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) return GetLastError(); + if (! WinPipe(&hChildStdinRd, &hChildStdinWr)) return GetLastError(); SetCurrentDirectory(dir); // go to engine directory