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
|
// This is the Win32 version of this struct
#if defined(_WIN32)
#include "win32/autopipe.h"
#else
#ifndef _AUTOPIPE_H
#define _AUTOPIPE_H
class autopipe {
autofd input, output;
public:
explicit autopipe(size_t pipe_size=4096) : input(-1), output(-1)
{
int fd[2];
if( pipe(fd)==0 ) {
input=autofd(fd[0]);
output=autofd(fd[1]);
} else {
#if defined(EXCEPT_CLASS)
throw EXCEPT_CLASS("Couldn't create pipe", errno );
#endif
}
}
// Default copy constructor and operator= do exactly what we want.
//autopipe( const autopipe &that )
//autopipe &operator=( const autopipe &that )
// As does default dtor
//~autopipe()
autofd &get_read()
{
return input;
}
const autofd &get_read() const
{
return input;
}
autofd &get_write()
{
return output;
}
const autofd &get_write() const
{
return output;
}
void clear_read()
{
input.clear();
}
void clear_write()
{
output.clear();
}
void clear()
{
clear_read();
clear_write();
}
};
#endif // _AUTOPIPE_H
#endif // _WIN32
|