#include <fcntl.h>\r
#include <string.h>\r
\r
-#ifdef _MSC_VER \r
-#define SLEEP() Sleep(1) \r
-#else \r
-#define SLEEP() usleep(10) \r
-#endif \r
-\r
// Set VARIANTS for in WinBoard variant feature. (With -s option this will always be reset to use "shogi".)\r
# define VARIANTS "normal,xiangqi"\r
\r
FILE *toE, *fromE;\r
int pid;\r
\r
+#ifdef WIN32\r
+WinPipe(HANDLE *hRd, HANDLE *hWr)\r
+{\r
+ SECURITY_ATTRIBUTES saAttr;\r
+\r
+ /* Set the bInheritHandle flag so pipe handles are inherited. */\r
+ saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);\r
+ saAttr.bInheritHandle = TRUE;\r
+ saAttr.lpSecurityDescriptor = NULL;\r
+\r
+ /* Create a pipe */\r
+ return CreatePipe(hRd, hWr, &saAttr, 0);\r
+}\r
+#endif\r
+\r
#define INIT 0\r
#define WAKEUP 1\r
#define PAUSE 2\r
Sync (int action)\r
{\r
#ifdef WIN32\r
- if(action == PAUSE) while(pause) SLEEP(); // in Windows we still rely on polling. :-(\r
+ static HANDLE hWr, hRd; DWORD d; char c;\r
+ switch(action) {\r
+ case INIT: WinPipe(&hRd, &hWr); break;\r
+ case WAKEUP: WriteFile(hWr, "\n", 1, &d, NULL); break;\r
+ case PAUSE: ReadFile(hRd, &c, 1, &d, NULL);\r
+ }\r
#else\r
static int syncPipe[2]; char c;\r
switch(action) {\r
#ifdef WIN32\r
HANDLE hChildStdinRd, hChildStdinWr,\r
hChildStdoutRd, hChildStdoutWr;\r
- SECURITY_ATTRIBUTES saAttr;\r
BOOL fSuccess;\r
PROCESS_INFORMATION piProcInfo;\r
STARTUPINFO siStartInfo;\r
DWORD err;\r
\r
- /* Set the bInheritHandle flag so pipe handles are inherited. */\r
- saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);\r
- saAttr.bInheritHandle = TRUE;\r
- saAttr.lpSecurityDescriptor = NULL;\r
-\r
/* Create a pipe for the child's STDOUT. */\r
- if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) return GetLastError();\r
+ if (! WinPipe(&hChildStdoutRd, &hChildStdoutWr)) return GetLastError();\r
\r
/* Create a pipe for the child's STDIN. */\r
- if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) return GetLastError();\r
+ if (! WinPipe(&hChildStdinRd, &hChildStdinWr)) return GetLastError();\r
\r
SetCurrentDirectory(dir); // go to engine directory\r
\r