X-Git-Url: http://winboard.nl/cgi-bin?p=polyglot.git;a=blobdiff_plain;f=pipe.h;h=d24ed8ca7386b0e55ec6c14a03dd2a6a010df457;hp=b13f5135ce0719656df83d5bfa7fa0d0e4d5b49b;hb=HEAD;hpb=64f72f31685ea1dff12b19b22cfaf7a53ccc079f diff --git a/pipe.h b/pipe.h index b13f513..d24ed8c 100644 --- a/pipe.h +++ b/pipe.h @@ -4,30 +4,60 @@ // includes #include - +#include +#include +#include // 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 + +#define PIPE_EOF 1 +#define PIPE_ACTIVE 2 // types -struct PipeStruct { - HANDLE hInput, hOutput; +class PipeStruct { + friend DWORD WINAPI ThreadProc(LPVOID lpParam); + public: HANDLE hProcess; - BOOL bConsole; - int nBytesLeft; - int nReadEnd; - char szBuffer[LINE_INPUT_MAX_CHAR]; - - void Open(const char *szExecFile = NULL); - void Close(void) const; - void ReadInput(void); - bool CheckInput(void); - bool GetBuffer(char *szLineStr); - bool LineInput(char *szLineStr); - void LineOutput(const char *szLineStr) const; -}; // pipe + 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 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); + int ReadData(void); + +}; + +// pipe #endif #endif