-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDuplicateStream.h
95 lines (88 loc) · 2.65 KB
/
DuplicateStream.h
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
/**********************************************************
* This software is part of the graphviz toolset *
* http://www.graphviz.org/ *
* *
* Copyright (c) 1994-2005 AT&T Corp. *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Corp. *
* *
* Information and Software Systems Research *
* AT&T Research, Florham Park NJ *
* *
* This version available from *
* http://dynagraph.org *
**********************************************************/
#ifndef DuplicateStream_h
#define DuplicateStream_h
#ifndef DYNAGRAPH_NO_THREADS
#include <boost/thread/thread.hpp>
#endif
#include <boost/thread/xtime.hpp>
#include <boost/bind/bind.hpp>
#include <fcntl.h>
#ifdef WIN32
#include <io.h>
inline void pipe(int fd[2]) {
const int pipe_buffer_size=20000;
_pipe(fd,pipe_buffer_size,_O_TEXT);
}
#define fdopen _fdopen //?
#else
#include <unistd.h>
#endif
extern bool g_xeptFatal;
extern int g_maxWait;
extern bool g_randomizeWait;
namespace Dynagraph {
struct DuplicateIn {
DuplicateIn(FILE *input, std::ostream &log);
~DuplicateIn() {
#ifndef DYNAGRAPH_NO_THREADS // this functionality also won't work
delete thread_;
#endif
}
FILE *getNewInput() {
return fromPipe_;
}
private:
FILE *input_,*toPipe_,*fromPipe_;
std::ostream &log_;
#ifndef DYNAGRAPH_NO_THREADS // this functionality also won't work
boost::thread *thread_;
#endif
const int RAND_MULT;
void go();
};
/* (unused)
struct DuplicateOut {
FILE *output_,*log_,*toPipe_,*fromPipe_;
boost::thread *thread_;
DuplicateIn(FILE *output, FILE *log) : output_(output), log_(log) {
int fd[2];
_pipe(fd,1000,_O_BINARY);
toPipe_ = fdopen(fd[1],"w");
setvbuf(toPipe_,0,_IONBF,0);
fromPipe_ = fdopen(fd[0],"r");
thread_ = new boost::thread(boost::bind(&DuplicateIn::go,this));
}
~DuplicateIn() {
delete thread_;
}
FILE *getNewOutput() {
return toPipe_;
}
void go() {
while(!feof(input_)) {
char buf[1000];
if(fgets(buf,1000,fromPipe_)) {
fputs(buf,log_);
fputs(buf,output_);
}
}
fclose(output_);
}
};
*/
} // namespace Dynagraph
#endif // DuplicateStream_h