version 1.4b27
[polyglot.git] / pipe.h
diff --git a/pipe.h b/pipe.h
index ced06d7..d24ed8c 100644 (file)
--- a/pipe.h
+++ b/pipe.h
@@ -4,10 +4,15 @@
 // includes
 
 #include <windows.h>
+#include <io.h>
+#include <fcntl.h>
+#include <stdio.h>
 
 // constants
 
-const int LINE_INPUT_MAX_CHAR = 4096;
+// This should be bigger than the maximum length of an engine output or GUI
+// input line.
+const int LINE_INPUT_MAX_CHAR = 40960;
 
 // defines
 
@@ -16,27 +21,43 @@ const int LINE_INPUT_MAX_CHAR = 4096;
 
 // types
 
-struct PipeStruct {
-
-    HANDLE hInput, hOutput;
+class  PipeStruct {
+  friend DWORD WINAPI ThreadProc(LPVOID lpParam);
+ public:
     HANDLE hProcess;
-    DWORD state;
-    BOOL bConsole;
-    int nBytesLeft;
-    int nReadEnd;
-    char szBuffer[LINE_INPUT_MAX_CHAR];
-
+    HANDLE hEvent;
+    bool GetBuffer(char *szLineStr);
+    void LineInput(char *szLineStr);
+    void LineOutput(const char *szLineStr) const;
     void Open(const char *szExecFile = NULL);
     void Close(void) const;
     void Kill(void) const;
-    bool EOF_(void);
     bool Active(void);
+    bool EOF_(void);
+ private:
+    HANDLE hInput, hOutput;
+    FILE *fpInput;
+    HANDLE hThread;
+    BOOL bConsole;
+    BOOL bPipe;
+
+    CRITICAL_SECTION CriticalSection;
+
+    volatile DWORD state;
+    volatile char * lpFeedEnd;
+    volatile int nReadEnd;
+    char lpBuffer[LINE_INPUT_MAX_CHAR];
+    char lpReadBuffer[LINE_INPUT_MAX_CHAR];
+
+    bool EOF_input(void);
+    void set_EOF_input(void);
+    void set_Active(void);
     void ReadInput(void);
-    bool CheckInput(void);
-    bool GetBuffer(char *szLineStr);
-    bool LineInput(char *szLineStr);
-    void LineOutput(const char *szLineStr) const;
-}; // pipe
+    int ReadData(void);
+
+};
+
+// pipe
 
 #endif
 #endif