File: pipex.h

package info (click to toggle)
polyglot 2.0.1%2Bgit20140926-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,228 kB
  • ctags: 1,163
  • sloc: ansic: 10,416; sh: 994; makefile: 18
file content (108 lines) | stat: -rw-r--r-- 2,285 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifndef PIPEX_H
#define PIPEX_H
#ifdef _WIN32

// WIN32 part

// includes

#include <windows.h>
#include <stdio.h>
#include "util.h"

// defines

#define PIPEX_EOF (1<<0)
#define PIPEX_ACTIVE (1<<1)

// This should be bigger than the maximum length of an engine output or GUI
// input line.

#define LINE_INPUT_MAX_CHAR 4096

// types

typedef struct {
    HANDLE hProcess;
    HANDLE hEvent;
    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];
    char szWriteBuffer[LINE_INPUT_MAX_CHAR];
    DWORD dwWriteIndex;
    const char *name;
    const char *command;
    BOOL quit_pending;

} pipex_t;

#else

// POSIX part

// includes

#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>


#include "io.h"
#include "util.h"

// defines

#define PIPEX_EOF (1<<0)
#define PIPEX_ACTIVE (1<<1)

// types

typedef struct {
    io_t io[1];
    pid_t pid;
    int state;
    bool quit_pending;
    const char *command;
} pipex_t;

#endif

// part common to WIN32 and POSIX

// macros

#define PIPEX_MAGIC "!@#$%"
#define WAIT_GRANULARITY 100

// functions 

extern void  pipex_open         (pipex_t *pipex, 
                                 const char *name,
                                 const char *working_dir,
                                 const char *command);
extern bool  pipex_active       (pipex_t *pipex);
extern bool  pipex_readln       (pipex_t *pipex, char *string);
extern bool  pipex_readln_nb    (pipex_t *pipex, char *string);
extern void  pipex_writeln      (pipex_t *pipex, const char *string);
extern void  pipex_write        (pipex_t *pipex, const char *string);
extern char* pipex_get_buffer   (pipex_t *pipex);
extern bool  pipex_eof          (pipex_t *pipex);
extern void  pipex_send_eof     (pipex_t *pipex);
extern void  pipex_exit         (pipex_t *pipex, int kill_timeout);
extern void  pipex_set_priority (pipex_t *pipex, int value);
extern void  pipex_set_affinity (pipex_t *pipex, int value);
extern void  pipex_wait_event   (pipex_t *pipex[]);


// pipex

#endif