blocxx
|
Abstract interface for an UnnamedPipe. More...
#include <UnnamedPipe.hpp>
Public Types | |
enum | EBlockingMode { E_NONBLOCKING, E_BLOCKING } |
enum | EOpen { E_DONT_OPEN, E_OPEN } |
Public Member Functions | |
virtual | ~UnnamedPipe () |
int | writeInt (int value) |
Write an int (native binary representation) to the pipe. | |
int | writeString (const String &strData) |
Writes a String to the pipe. | |
int | readInt (int *value) |
Reads an int (native binary representation) from the pipe. | |
int | readString (String &strData) |
Reads a String from the pipe. | |
void | setReadTimeout (const Timeout &timeout) |
Sets the read timeout value. | |
BLOCXX_DEPRECATED void | setReadTimeout (int seconds) |
Timeout | getReadTimeout () |
Gets the read timeout value. | |
void | setWriteTimeout (const Timeout &timeout) |
Sets the write timeout value. | |
BLOCXX_DEPRECATED void | setWriteTimeout (int seconds) |
Timeout | getWriteTimeout () |
Gets the write timeout value. | |
void | setTimeouts (const Timeout &timeout) |
Sets the read & write timeout values. | |
BLOCXX_DEPRECATED void | setTimeouts (int seconds) |
String | readAll () |
Read from the pipe and collect into a string, until the other end of the pipe is closed. | |
virtual void | open ()=0 |
Open the pipe. | |
virtual int | close ()=0 |
Close the pipe. | |
virtual bool | isOpen () const =0 |
Is the pipe open or closed? | |
virtual Select_t | getReadSelectObj () const =0 |
Get the read select object. | |
virtual Select_t | getWriteSelectObj () const =0 |
Get the write select object. | |
virtual void | setBlocking (EBlockingMode isBlocking=E_BLOCKING)=0 |
Set the pipe's blocking mode. | |
virtual void | setWriteBlocking (EBlockingMode isBlocking=E_BLOCKING)=0 |
Set blocking mode for writing to pipe. | |
virtual void | setReadBlocking (EBlockingMode isBlocking=E_BLOCKING)=0 |
Set blocking mode for reading from pipe. | |
virtual EBlockingMode | getReadBlocking () const =0 |
Get the current blocking mode for reading from pipe. | |
virtual EBlockingMode | getWriteBlocking () const =0 |
Get the current blocking mode for writing from pipe. | |
virtual Descriptor | getInputDescriptor () const =0 |
Get the underlying input descriptor. | |
virtual Descriptor | getOutputDescriptor () const =0 |
Get the underlying output descriptor. | |
virtual void | passDescriptor (Descriptor h, const UnnamedPipeRef &ackPipe=0, const ProcessRef &targetProcess=0)=0 |
Sends a Descriptor to the peer. | |
virtual AutoDescriptor | receiveDescriptor (const UnnamedPipeRef &ackPipe=0)=0 |
Gets a Descriptor from the peer. | |
virtual int | closeInputHandle ()=0 |
virtual int | closeOutputHandle ()=0 |
Static Public Member Functions | |
static UnnamedPipeRef | createUnnamedPipe (EOpen doOpen=E_OPEN) |
Create an instance of the concrete class that implements the UnnamedPipe interface. | |
static UnnamedPipeRef | createUnnamedPipeFromDescriptor (AutoDescriptor inputAndOutput) |
Create an instance of the concrete class that implements the UnnamedPipe interface connected bidirectionally to the specified descriptor. | |
static UnnamedPipeRef | createUnnamedPipeFromDescriptor (AutoDescriptor input, AutoDescriptor output) |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to the specified descriptors. | |
static void | createConnectedPipes (UnnamedPipeRef &first, UnnamedPipeRef &second) |
Create a connected pair of pipes. | |
static UnnamedPipeRef | createStdin () |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to stdin. | |
static UnnamedPipeRef | createStdout () |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to stdout. | |
static UnnamedPipeRef | createStdinStdout () |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to stdin and stdout. | |
static UnnamedPipeRef | createStderr () |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to stderr. | |
Static Public Attributes | |
static const int | INFINITE_TIMEOUT = -1 |
Protected Member Functions | |
UnnamedPipe () | |
Private Attributes | |
Timeout | m_readTimeout |
Timeout | m_writeTimeout |
Abstract interface for an UnnamedPipe.
Blocking is enabled by default.
Definition at line 60 of file UnnamedPipe.hpp.
Definition at line 192 of file UnnamedPipe.hpp.
Definition at line 263 of file UnnamedPipe.hpp.
BLOCXX_NAMESPACE::UnnamedPipe::~UnnamedPipe | ( | ) | [virtual] |
Definition at line 65 of file UnnamedPipe.cpp.
BLOCXX_NAMESPACE::UnnamedPipe::UnnamedPipe | ( | ) | [inline, protected] |
Definition at line 331 of file UnnamedPipe.hpp.
virtual int BLOCXX_NAMESPACE::UnnamedPipe::close | ( | ) | [pure virtual] |
Close the pipe.
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
virtual int BLOCXX_NAMESPACE::UnnamedPipe::closeInputHandle | ( | ) | [pure virtual] |
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
virtual int BLOCXX_NAMESPACE::UnnamedPipe::closeOutputHandle | ( | ) | [pure virtual] |
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
void BLOCXX_NAMESPACE::UnnamedPipe::createConnectedPipes | ( | UnnamedPipeRef & | first, |
UnnamedPipeRef & | second | ||
) | [static] |
Create a connected pair of pipes.
The input from first will be connected to the output of second, and the input from second will be connected to the output of first. The pipes default to have 10 minute timeouts.
first | The first pipe. |
second | The second pipe. |
UnnamedPipeException | with error code EMFILE if too many descriptors are in use by the process. |
Definition at line 244 of file UnnamedPipe.cpp.
References BLOCXX_THROW_ERRNO_MSG, and createUnnamedPipeFromDescriptor().
UnnamedPipeRef BLOCXX_NAMESPACE::UnnamedPipe::createStderr | ( | ) | [static] |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to stderr.
Definition at line 198 of file UnnamedPipe.cpp.
References BLOCXX_INVALID_HANDLE, BLOCXX_THROW_ERRNO_MSG, and BLOCXX_NAMESPACE::AutoResource< Policy >::get().
UnnamedPipeRef BLOCXX_NAMESPACE::UnnamedPipe::createStdin | ( | ) | [static] |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to stdin.
Definition at line 142 of file UnnamedPipe.cpp.
References BLOCXX_INVALID_HANDLE, BLOCXX_THROW_ERRNO_MSG, and BLOCXX_NAMESPACE::AutoResource< Policy >::get().
UnnamedPipeRef BLOCXX_NAMESPACE::UnnamedPipe::createStdinStdout | ( | ) | [static] |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to stdin and stdout.
Definition at line 176 of file UnnamedPipe.cpp.
References BLOCXX_INVALID_HANDLE, BLOCXX_THROW_ERRNO_MSG, and BLOCXX_NAMESPACE::AutoResource< Policy >::get().
UnnamedPipeRef BLOCXX_NAMESPACE::UnnamedPipe::createStdout | ( | ) | [static] |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to stdout.
Definition at line 159 of file UnnamedPipe.cpp.
References BLOCXX_INVALID_HANDLE, BLOCXX_THROW_ERRNO_MSG, and BLOCXX_NAMESPACE::AutoResource< Policy >::get().
UnnamedPipeRef BLOCXX_NAMESPACE::UnnamedPipe::createUnnamedPipe | ( | EOpen | doOpen = E_OPEN | ) | [static] |
Create an instance of the concrete class that implements the UnnamedPipe interface.
The input and output of the pipe will be connected. The pipe defaults to have 10 minute timeouts.
doOpen | Open the pipe or not. |
Definition at line 130 of file UnnamedPipe.cpp.
Referenced by BLOCXX_NAMESPACE::Socket::createShutDownMechanism(), and BLOCXX_NAMESPACE::PosixExec::spawnImpl().
UnnamedPipeRef BLOCXX_NAMESPACE::UnnamedPipe::createUnnamedPipeFromDescriptor | ( | AutoDescriptor | input, |
AutoDescriptor | output | ||
) | [static] |
Create an instance of the concrete class that implements the UnnamedPipe interface connected to the specified descriptors.
input | The input descriptor to connect. |
output | The output descriptor to connect. |
Definition at line 232 of file UnnamedPipe.cpp.
References createUnnamedPipeFromDescriptor().
UnnamedPipeRef BLOCXX_NAMESPACE::UnnamedPipe::createUnnamedPipeFromDescriptor | ( | AutoDescriptor | inputAndOutput | ) | [static] |
Create an instance of the concrete class that implements the UnnamedPipe interface connected bidirectionally to the specified descriptor.
inputAndOutput | The input and output descriptor to connect. |
Definition at line 215 of file UnnamedPipe.cpp.
References BLOCXX_INVALID_HANDLE, BLOCXX_THROW_ERRNO_MSG, and BLOCXX_NAMESPACE::AutoResource< Policy >::get().
Referenced by createConnectedPipes(), and createUnnamedPipeFromDescriptor().
virtual Descriptor BLOCXX_NAMESPACE::UnnamedPipe::getInputDescriptor | ( | ) | const [pure virtual] |
Get the underlying input descriptor.
The UnnamedPipe instance retains ownership of the descriptor.
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
Referenced by BLOCXX_NAMESPACE::Exec::PreExec::closePipesOnExec().
virtual Descriptor BLOCXX_NAMESPACE::UnnamedPipe::getOutputDescriptor | ( | ) | const [pure virtual] |
Get the underlying output descriptor.
The UnnamedPipe instance retains ownership of the descriptor.
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
Referenced by BLOCXX_NAMESPACE::Exec::PreExec::closePipesOnExec().
virtual EBlockingMode BLOCXX_NAMESPACE::UnnamedPipe::getReadBlocking | ( | ) | const [pure virtual] |
Get the current blocking mode for reading from pipe.
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
virtual Select_t BLOCXX_NAMESPACE::UnnamedPipe::getReadSelectObj | ( | ) | const [pure virtual] |
Get the read select object.
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
Timeout BLOCXX_NAMESPACE::UnnamedPipe::getReadTimeout | ( | ) | [inline] |
Gets the read timeout value.
If blocking is enabled this is the number of seconds a read operation will block. Exception safety: No-throw
Definition at line 126 of file UnnamedPipe.hpp.
Referenced by BLOCXX_NAMESPACE::PosixUnnamedPipe::read(), and BLOCXX_NAMESPACE::PosixUnnamedPipe::receiveDescriptor().
virtual EBlockingMode BLOCXX_NAMESPACE::UnnamedPipe::getWriteBlocking | ( | ) | const [pure virtual] |
Get the current blocking mode for writing from pipe.
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
virtual Select_t BLOCXX_NAMESPACE::UnnamedPipe::getWriteSelectObj | ( | ) | const [pure virtual] |
Get the write select object.
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
Timeout BLOCXX_NAMESPACE::UnnamedPipe::getWriteTimeout | ( | ) | [inline] |
Gets the write timeout value.
If blocking is enabled this is the number of seconds a write operation will block. Exception safety: No-throw
Definition at line 143 of file UnnamedPipe.hpp.
Referenced by BLOCXX_NAMESPACE::PosixUnnamedPipe::passDescriptor(), and BLOCXX_NAMESPACE::PosixUnnamedPipe::write().
virtual bool BLOCXX_NAMESPACE::UnnamedPipe::isOpen | ( | ) | const [pure virtual] |
Is the pipe open or closed?
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
virtual void BLOCXX_NAMESPACE::UnnamedPipe::open | ( | ) | [pure virtual] |
Open the pipe.
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
virtual void BLOCXX_NAMESPACE::UnnamedPipe::passDescriptor | ( | Descriptor | h, |
const UnnamedPipeRef & | ackPipe = 0 , |
||
const ProcessRef & | targetProcess = 0 |
||
) | [pure virtual] |
Sends a Descriptor
to the peer.
h | The Descriptor to send. |
IOException | on I/O error. |
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
String BLOCXX_NAMESPACE::UnnamedPipe::readAll | ( | ) |
Read from the pipe and collect into a string, until the other end of the pipe is closed.
Exception safety: Strong for the C++ instance. Fubared for the pipe. If an exception is thrown, the pipe won't be reset to it's pre-call state.
IOException | on error |
Definition at line 113 of file UnnamedPipe.cpp.
References BLOCXX_NAMESPACE::IOIFC::E_THROW_ON_ERROR, BLOCXX_NAMESPACE::IOIFC::read(), and BLOCXX_NAMESPACE::StringBuffer::releaseString().
int BLOCXX_NAMESPACE::UnnamedPipe::readInt | ( | int * | value | ) |
Reads an int (native binary representation) from the pipe.
If blocking is enabled, readInt() will block for up to getReadTimeout() seconds or forever if getReadTimeout() == -1. Exception safety: No-throw
value | Out parameter where the read int will be stored. |
Definition at line 88 of file UnnamedPipe.cpp.
References BLOCXX_NAMESPACE::IOIFC::read().
Referenced by readString().
int BLOCXX_NAMESPACE::UnnamedPipe::readString | ( | String & | strData | ) |
Reads a String from the pipe.
If blocking is enabled, readInt() will block for up to getReadTimeout() seconds or forever if getReadTimeout() == -1. Exception safety: Strong for the C++ instance. Fubared for the pipe. If an exception is thrown, the pipe won't be reset to it's pre-call state.
strData | Out parameter where the read int will be stored. |
std::bad_alloc |
Definition at line 94 of file UnnamedPipe.cpp.
References BLOCXX_NAMESPACE::String::E_TAKE_OWNERSHIP, BLOCXX_NAMESPACE::AutoPtrVec< X >::get(), BLOCXX_NAMESPACE::IOIFC::read(), readInt(), and BLOCXX_NAMESPACE::AutoPtrVec< X >::release().
virtual AutoDescriptor BLOCXX_NAMESPACE::UnnamedPipe::receiveDescriptor | ( | const UnnamedPipeRef & | ackPipe = 0 | ) | [pure virtual] |
Gets a Descriptor
from the peer.
Descriptor
sent by the peer.IOException | on I/O error or if the peer does not send a Descriptor |
Implemented in BLOCXX_NAMESPACE::PosixUnnamedPipe.
virtual void BLOCXX_NAMESPACE::UnnamedPipe::setBlocking | ( | EBlockingMode | isBlocking = E_BLOCKING | ) | [pure virtual] |
Set the pipe's blocking mode.
Precondition: The pipe is open.
isBlocking | new blocking mode. |
virtual void BLOCXX_NAMESPACE::UnnamedPipe::setReadBlocking | ( | EBlockingMode | isBlocking = E_BLOCKING | ) | [pure virtual] |
Set blocking mode for reading from pipe.
Precondition: The pipe input is open.
isBlocking | new read blocking mode. |
void BLOCXX_NAMESPACE::UnnamedPipe::setReadTimeout | ( | const Timeout & | timeout | ) | [inline] |
Sets the read timeout value.
If blocking is enabled this is the number of seconds a read operation will block. Exception safety: No-throw
timeout | The new read timeout. |
Definition at line 117 of file UnnamedPipe.hpp.
BLOCXX_DEPRECATED void BLOCXX_NAMESPACE::UnnamedPipe::setReadTimeout | ( | int | seconds | ) | [inline] |
Definition at line 118 of file UnnamedPipe.hpp.
References BLOCXX_NAMESPACE::Timeout::relative().
BLOCXX_DEPRECATED void BLOCXX_NAMESPACE::UnnamedPipe::setTimeouts | ( | int | seconds | ) | [inline] |
Definition at line 152 of file UnnamedPipe.hpp.
References BLOCXX_NAMESPACE::Timeout::relative().
void BLOCXX_NAMESPACE::UnnamedPipe::setTimeouts | ( | const Timeout & | timeout | ) | [inline] |
Sets the read & write timeout values.
If blocking is enabled this is the number of seconds a read or write operation will block. Exception safety: No-throw
timeout | The new timeout. |
Definition at line 151 of file UnnamedPipe.hpp.
virtual void BLOCXX_NAMESPACE::UnnamedPipe::setWriteBlocking | ( | EBlockingMode | isBlocking = E_BLOCKING | ) | [pure virtual] |
Set blocking mode for writing to pipe.
Precondition: The pipe output is open.
isBlocking | new write blocking mode. |
void BLOCXX_NAMESPACE::UnnamedPipe::setWriteTimeout | ( | const Timeout & | timeout | ) | [inline] |
Sets the write timeout value.
If blocking is enabled this is the number of seconds a write operation will block. Exception safety: No-throw
timeout | The new write timeout. |
Definition at line 134 of file UnnamedPipe.hpp.
BLOCXX_DEPRECATED void BLOCXX_NAMESPACE::UnnamedPipe::setWriteTimeout | ( | int | seconds | ) | [inline] |
Definition at line 135 of file UnnamedPipe.hpp.
References BLOCXX_NAMESPACE::Timeout::relative().
int BLOCXX_NAMESPACE::UnnamedPipe::writeInt | ( | int | value | ) |
Write an int (native binary representation) to the pipe.
If blocking is enabled, writeInt() will block for up to getWriteTimeout() seconds or forever if getWriteTimeout() == -1. Exception safety: No-throw
value | The value to write. |
Definition at line 70 of file UnnamedPipe.cpp.
References BLOCXX_NAMESPACE::IOIFC::write().
Referenced by writeString().
int BLOCXX_NAMESPACE::UnnamedPipe::writeString | ( | const String & | strData | ) |
Writes a String to the pipe.
This should be read from the other side by readString. If blocking is enabled, writeString() will block for up to getWriteTimeout() seconds or forever if getWriteTimeout() == -1. Exception safety: No-throw
strData | The String to write. |
Definition at line 76 of file UnnamedPipe.cpp.
References BLOCXX_NAMESPACE::String::c_str(), BLOCXX_NAMESPACE::String::length(), BLOCXX_NAMESPACE::IOIFC::write(), and writeInt().
const int BLOCXX_NAMESPACE::UnnamedPipe::INFINITE_TIMEOUT = -1 [static] |
Definition at line 109 of file UnnamedPipe.hpp.
Definition at line 336 of file UnnamedPipe.hpp.
Definition at line 337 of file UnnamedPipe.hpp.