version 1.4w10UCIb24
[polyglot.git] / pipe.h
1 #ifndef PIPE_H
2 #define PIPE_H
3 #ifdef _WIN32
4 // includes
5
6 #include <windows.h>
7 #include <io.h>
8 #include <fcntl.h>
9 #include <stdio.h>
10
11 // constants
12
13 // This should be bigger than the maximum length of an engine output or GUI
14 // input line.
15 const int LINE_INPUT_MAX_CHAR = 40960;
16
17 // defines
18
19 #define PIPE_EOF 1
20 #define PIPE_ACTIVE 2
21
22 // types
23
24 struct PipeStruct {
25
26     HANDLE hInput, hOutput;
27     FILE *fpInput;
28     HANDLE hProcess;
29     HANDLE hThread;
30     HANDLE hEvent;
31     BOOL bConsole;
32     BOOL bPipe;
33
34     CRITICAL_SECTION CriticalSection;
35
36     volatile DWORD state;
37     volatile char * lpFeedEnd;
38     volatile int nReadEnd;
39     char lpBuffer[LINE_INPUT_MAX_CHAR];
40     char lpReadBuffer[LINE_INPUT_MAX_CHAR];
41
42     void Open(const char *szExecFile = NULL);
43     void Close(void) const;
44     void Kill(void) const;
45     bool EOF_(void);
46     void set_EOF_(void);
47     bool Active(void);
48     void set_Active(void);
49     void ReadInput(void);
50     int ReadData(void);
51     bool GetBuffer(char *szLineStr);
52     void LineInput(char *szLineStr);
53     void LineOutput(const char *szLineStr) const;
54
55 };
56
57 // pipe
58
59 #endif
60 #endif