| 1 |
#ifndef INCLUDED_PIPE_H_ |
| 2 |
#define INCLUDED_PIPE_H_ |
| 3 |
|
| 4 |
#include <cstddef> |
| 5 |
|
| 6 |
namespace FBB |
| 7 |
{ |
| 8 |
class Pipe |
| 9 |
{ |
| 10 |
protected: |
| 11 |
int d_fd[2]; |
| 12 |
|
| 13 |
public: |
| 14 |
enum bad_pipe {}; |
| 15 |
enum redirection_failed {}; |
| 16 |
|
| 17 |
Pipe(); |
| 18 |
Pipe(int socket) |
| 19 |
{ |
| 20 |
d_fd[READ] = socket; |
| 21 |
d_fd[WRITE] = socket; |
| 22 |
} |
| 23 |
Pipe(int const *fd) |
| 24 |
{ |
| 25 |
d_fd[READ] = fd[READ]; |
| 26 |
d_fd[WRITE] = fd[WRITE]; |
| 27 |
} |
| 28 |
|
| 29 |
// readVia(): set up redirection from d_fd[READ] to the given |
| 30 |
// filedescriptor(s): reading from d_fd[READ] |
| 31 |
// is done via the filedescriptor(s) |
| 32 |
void readVia(int filedescriptor); |
| 33 |
// not tested: |
| 34 |
void readVia(int const *filedescriptor, size_t n); |
| 35 |
|
| 36 |
// writeVia(): set up redirection from d_fd[WRITE] to the given |
| 37 |
// filedescriptor(s): writing to d_fd[WRITE] |
| 38 |
// is done via the filedescriptor(s) |
| 39 |
void writeVia(int filedescriptor); |
| 40 |
void writeVia(int const *filedescriptor, size_t n = 2); |
| 41 |
|
| 42 |
int readFd() |
| 43 |
{ |
| 44 |
return d_fd[READ]; |
| 45 |
} |
| 46 |
int writeFd() |
| 47 |
{ |
| 48 |
return d_fd[WRITE]; |
| 49 |
} |
| 50 |
|
| 51 |
protected: |
| 52 |
enum RW { READ, WRITE }; |
| 53 |
|
| 54 |
private: |
| 55 |
void dup(RW rw, int fd); |
| 56 |
|
| 57 |
Pipe(Pipe const &other); // NI |
| 58 |
Pipe &operator=(Pipe const &other); // NI |
| 59 |
}; |
| 60 |
} |
| 61 |
|
| 62 |
#endif |