Add forgotten files 1.4.70b
[polyglot.git] / pipex.h
1 #ifndef PIPEX_H
2 #define PIPEX_H
3 #ifdef _WIN32
4
5 // WIN32 part
6
7 // includes
8
9 #include <windows.h>
10 #include <stdio.h>
11 #include "util.h"
12
13 // defines
14
15 #define PIPEX_EOF (1<<0)
16 #define PIPEX_ACTIVE (1<<1)
17
18 // This should be bigger than the maximum length of an engine output or GUI
19 // input line.
20
21 #define LINE_INPUT_MAX_CHAR 4096
22
23 // types
24
25 typedef struct {
26     HANDLE hProcess;
27     HANDLE hEvent;
28     HANDLE hInput, hOutput;
29     FILE *fpInput;
30     HANDLE hThread;
31     BOOL bConsole;
32     BOOL bPipe;
33     CRITICAL_SECTION CriticalSection;
34     volatile DWORD state;
35     volatile char * lpFeedEnd;
36     volatile int nReadEnd;
37     char lpBuffer[LINE_INPUT_MAX_CHAR];
38     char lpReadBuffer[LINE_INPUT_MAX_CHAR];
39     char szWriteBuffer[LINE_INPUT_MAX_CHAR];
40     DWORD dwWriteIndex;
41     const char *name;
42     const char *command;
43     BOOL quit_pending;
44
45 } pipex_t;
46
47 #else
48
49 // POSIX part
50
51 // includes
52
53 #include <sys/types.h>
54 #include <unistd.h>
55 #include <sys/time.h>
56 #include <sys/resource.h>
57
58
59 #include "io.h"
60 #include "util.h"
61
62 // defines
63
64 #define PIPEX_EOF (1<<0)
65 #define PIPEX_ACTIVE (1<<1)
66
67 // types
68
69 typedef struct {
70     io_t io[1];
71     pid_t pid;
72     int state;
73     bool quit_pending;
74     const char *command;
75 } pipex_t;
76
77 #endif
78
79 // part common to WIN32 and POSIX
80
81 // macros
82
83 #define PIPEX_MAGIC "!@#$%"
84 #define WAIT_GRANULARITY 100
85
86 // functions 
87
88 extern void  pipex_open         (pipex_t *pipex, 
89                                  const char *name,
90                                  const char *working_dir,
91                                  const char *command);
92 extern bool  pipex_active       (pipex_t *pipex);
93 extern bool  pipex_readln       (pipex_t *pipex, char *string);
94 extern bool  pipex_readln_nb    (pipex_t *pipex, char *string);
95 extern void  pipex_writeln      (pipex_t *pipex, const char *string);
96 extern void  pipex_write        (pipex_t *pipex, const char *string);
97 extern char* pipex_get_buffer   (pipex_t *pipex);
98 extern bool  pipex_eof          (pipex_t *pipex);
99 extern void  pipex_send_eof     (pipex_t *pipex);
100 extern void  pipex_exit         (pipex_t *pipex, int kill_timeout);
101 extern void  pipex_set_priority (pipex_t *pipex, int value);
102 extern void  pipex_set_affinity (pipex_t *pipex, int value);
103 extern void  pipex_wait_event   (pipex_t *pipex[]);
104
105
106 // pipex
107
108 #endif