01:
02:
03: #ifndef _DemandWrapper_HH
04: #define _DemandWrapper_HH 1
05:
06: #include <unistd.h>
07: #include <sys/types.h>
08: #include <sys/wait.h>
09:
10: #include "RZError.hh"
11: #include "ExtractWrapper.hh"
12: #include "ConReservation.hh"
13:
14:
15:
16: namespace RZ {
17: inline void closer(int const fileno)
18: {
19: while (close(fileno) == -1 && errno == EINTR);
20: IOError::what_if("Can't close!");
21: }
22:
23: struct Piper {
24: int file_no;
25:
26: Piper(int f = -1): file_no(f) {}
27: void operator=(int f) { file_no = f; }
28: bool operator!(void) { return file_no == -1; }
29:
30: void close()
31: {
32: if (file_no != -1) {
33: closer(file_no);
34: file_no = -1;
35: }
36: }
37: };
38:
39: struct Worker: Piper {
40: int process_id;
41:
42: Worker(): process_id(-1) {}
43:
44: void close()
45: {
46: Piper::close();
47: if (process_id != -1) {
48: int status = 0;
49: if (process_id != waitpid(process_id, &status, 0))
50: throw AssertionError();
51: process_id = -1;
52: }
53: }
54: };
55:
56: extern struct FullWrapper rz_wrapper;
57: extern struct ConTable rz_tab;
58: }
59:
60:
61:
62:
63:
64: #endif