Posix pipe.
More...
#include <Pipe.hpp>
Public Member Functions |
| Pipe () |
| Constructor for the pipe.
|
virtual | ~Pipe () |
| Destructor.
|
PosixDescriptor * | getReadDescriptor () |
| Get the write endpoint.
|
PosixDescriptor * | getWriteDescriptor () |
| Get the read endpoint.
|
int | read (Buffer *b, size_t size) |
| Method to read from the pipe and fill a buffer.
|
int | read (void *p, size_t size) |
| Method to read from the pipe.
|
int | write (Buffer *b, size_t size) |
| Method to write data in a buffer to the pipe.
|
int | write (const void *p, size_t size) |
| Method to write in the pipe.
|
int | write (const std::string &s) |
| Method to write a string in the pipe.
|
void | close () |
| Method to close the pipe.
|
long int | getRealCapacity () const |
| Get real capacity of the pipe.
|
Static Public Member Functions |
static long int | getPosixCapacity () |
| Get posix capacity of the pipe.
|
Private Member Functions |
| Pipe (const Pipe &) |
Detailed Description
Posix pipe.
This class wraps two PosixDescriptors because in some circumstances (e.g., after a fork()) the code wants to explicitly close one of the endpoints. The getReadDescriptor() and getWriteDescriptor() methods allow to get the PosixDescriptor and explicitly close it.
Definition at line 41 of file Pipe.hpp.
Constructor & Destructor Documentation
Constructor for the pipe.
- Exceptions
-
runtime_error | in case of error |
Definition at line 21 of file Pipe.cpp.
{
int fd[2];
if (pipe(fd) != 0) {
throw std::runtime_error ("Open pipe error");
}
read_ =
new PosixDescriptor(fd[0]);
write_ =
new PosixDescriptor(fd[1]);
}
Member Function Documentation
Method to close the pipe.
Note: currently there is no method to re-open the pipe.
Definition at line 157 of file Pipe.hpp.
static long int getPosixCapacity |
( |
| ) |
|
|
inlinestatic |
Get posix capacity of the pipe.
- Returns
- capacity of the pipe based on the Posix standard
Definition at line 167 of file Pipe.hpp.
{
return _POSIX_PIPE_BUF;
}
Get the write endpoint.
This method is useful if we want to explicitly close the read endpoint.
- Returns
- A pointer to the PosixDescriptor for reading
Definition at line 71 of file Pipe.hpp.
long int getRealCapacity |
( |
| ) |
const |
|
inline |
Get real capacity of the pipe.
- Returns
- real capacity of the pipe
Definition at line 176 of file Pipe.hpp.
Get the read endpoint.
This method is useful if we want to explicitly close the write endpoint.
- Returns
- A pointer to the PosixDescriptor for writing
Definition at line 82 of file Pipe.hpp.
int read |
( |
Buffer * |
b, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Method to read from the pipe and fill a buffer.
Note: this method may block current thread if data is not available. The buffer is filled with the read data.
- Parameters
-
b | Pointer to the buffer to be filled |
size | Number of bytes that must be read |
- Returns
- -1 in case of error; the number of bytes read otherwise
Definition at line 96 of file Pipe.hpp.
int read |
( |
void * |
p, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Method to read from the pipe.
Note: this method may block current thread if data is not available. The buffer is filled with the read data.
- Parameters
-
p | Pointer to the memory space to be filled |
size | Number of bytes that must be read |
- Returns
- -1 in case of error; the number of bytes read otherwise
Definition at line 110 of file Pipe.hpp.
int write |
( |
Buffer * |
b, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Method to write data in a buffer to the pipe.
Note: this method may block current thread if data cannot be written.
- Parameters
-
b | Pointer to the buffer to be filled |
size | Number of bytes that must be written |
- Returns
- -1 in case of error; the number of bytes read otherwise
Definition at line 123 of file Pipe.hpp.
int write |
( |
const void * |
p, |
|
|
size_t |
size |
|
) |
| |
|
inline |
Method to write in the pipe.
Note: this method may block current thread if data cannot be written.
- Parameters
-
p | Pointer to the memory space containing data |
size | Number of bytes that must be written |
- Returns
- -1 in case of error; the number of bytes read otherwise
Definition at line 136 of file Pipe.hpp.
int write |
( |
const std::string & |
s | ) |
|
|
inline |
Method to write a string in the pipe.
Note: this method may block current thread if data cannot be written.
- Parameters
-
- Returns
- -1 in case of error; the number of bytes read otherwise
Definition at line 148 of file Pipe.hpp.
Member Data Documentation
The documentation for this class was generated from the following files:
- /home/cloud/work/onposix-code/include/Pipe.hpp
- /home/cloud/work/onposix-code/src/Pipe.cpp