ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

ucommon::pipestream Class Reference

#include <stream.h>

Inheritance diagram for ucommon::pipestream:
[legend]
Collaboration diagram for ucommon::pipestream:
[legend]

Public Types

enum  access_t { RDONLY, WRONLY, RDWR }
 

Public Member Functions

 pipestream ()
 
 pipestream (const char *command, access_t access, char **args, char **env=NULL, size_t size=512)
 
virtual ~pipestream ()
 
 operator bool () const
 
bool operator! () const
 
void open (const char *path, access_t access, char **args, char **env=NULL, size_t buffering=512)
 
int close (void)
 
void terminate (void)
 
void cancel (void)
 
- Public Member Functions inherited from ucommon::StreamBuffer
int sync (void)
 
bool is_open (void) const
 
 operator bool () const
 
bool operator! () const
 

Protected Member Functions

void release (void)
 
int underflow (void) __OVERRIDE
 
int overflow (int ch) __OVERRIDE
 
- Protected Member Functions inherited from ucommon::StreamBuffer
 StreamBuffer ()
 
int uflow () __OVERRIDE
 
void release (void)
 
void allocate (size_t size)
 

Protected Attributes

fsys_t rd
 
fsys_t wr
 
shell::pid_t pid
 
- Protected Attributes inherited from ucommon::StreamBuffer
size_t bufsize
 
char * gbuf
 
char * pbuf
 

Private Member Functions

__LOCAL void allocate (size_t size, access_t mode)
 
 __DELETE_COPY (pipestream)
 

Detailed Description

Streamable pipe socket connection. This creates a stream between a parent and child process. As a stream class, data can be exchanged using the << and >> operators.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 237 of file stream.h.

Member Enumeration Documentation

◆ access_t

Enumerator
RDONLY 
WRONLY 
RDWR 

Definition at line 240 of file stream.h.

Constructor & Destructor Documentation

◆ pipestream() [1/2]

ucommon::pipestream::pipestream ( )

Create an unopened pipe stream.

Definition at line 405 of file stream.cpp.

◆ pipestream() [2/2]

ucommon::pipestream::pipestream ( const char *  command,
access_t  access,
char **  args,
char **  env = NULL,
size_t  size = 512 
)

Create child process and start pipe.

Parameters
pathto execute.
accessmode of pipe stream.
argsto pass to command.
envto create in child.
sizeof buffer.

Definition at line 410 of file stream.cpp.

References open().

◆ ~pipestream()

ucommon::pipestream::~pipestream ( )
virtual

Destroy a pipe stream.

Definition at line 416 of file stream.cpp.

References close().

Member Function Documentation

◆ __DELETE_COPY()

ucommon::pipestream::__DELETE_COPY ( pipestream  )
private

◆ allocate()

void ucommon::pipestream::allocate ( size_t  size,
access_t  mode 
)
private

◆ cancel()

void ucommon::pipestream::cancel ( void  )
inline

Definition at line 335 of file stream.h.

◆ close()

int ucommon::pipestream::close ( void  )

Close an active stream connection. This waits for the child to terminate.

Definition at line 609 of file stream.cpp.

References ucommon::StreamBuffer::bufsize, pid, release(), ucommon::StreamBuffer::sync(), and ucommon::shell::wait().

Referenced by open(), overflow(), terminate(), underflow(), and ~pipestream().

◆ open()

void ucommon::pipestream::open ( const char *  path,
access_t  access,
char **  args,
char **  env = NULL,
size_t  buffering = 512 
)

Open a stream connection to a pipe service.

Parameters
pathto execute.
accessmode of stream.
argsto pass to command.
envto create in child process.
bufferingsize to use.

Definition at line 561 of file stream.cpp.

References allocate(), ucommon::fsys::assign(), close(), ucommon::fsys::inherit(), input, INVALID_HANDLE_VALUE, INVALID_PID_VALUE, ucommon::fsys::null(), output, pid, ucommon::fsys::pipe(), rd, RDONLY, RDWR, ucommon::fsys::release(), ucommon::shell::spawn(), wr, and WRONLY.

Referenced by pipestream().

◆ operator bool()

ucommon::pipestream::operator bool ( ) const
inline

See if stream connection is active.

Returns
true if stream is active.

Definition at line 302 of file stream.h.

◆ operator!()

bool ucommon::pipestream::operator! ( void  ) const
inline

See if stream is disconnected.

Returns
true if stream disconnected.

Definition at line 310 of file stream.h.

◆ overflow()

int ucommon::pipestream::overflow ( int  ch)
protected

This streambuf method is used to write the output buffer through the established pipe connection.

Parameters
chchar to push through.
Returns
char pushed through.

Definition at line 510 of file stream.cpp.

References ucommon::StreamBuffer::bufsize, ch, close(), EOF, IS_EOF, ucommon::StreamBuffer::pbuf, PUT, wr, and ucommon::fsys::write().

◆ release()

void ucommon::pipestream::release ( void  )
protected

Release the stream, detach/do not wait for the process.

Definition at line 429 of file stream.cpp.

References ucommon::StreamBuffer::gbuf, ucommon::StreamBuffer::pbuf, rd, ucommon::StreamBuffer::release(), ucommon::fsys::release(), and wr.

Referenced by close().

◆ terminate()

void ucommon::pipestream::terminate ( void  )

Force terminate child and close.

Definition at line 421 of file stream.cpp.

References ucommon::StreamBuffer::bufsize, ucommon::shell::cancel(), close(), and pid.

◆ underflow()

int ucommon::pipestream::underflow ( void  )
protected

This streambuf method is used to load the input buffer through the established pipe connection.

Returns
char from get buffer, EOF if not connected.

Definition at line 471 of file stream.cpp.

References ucommon::StreamBuffer::bufsize, ch, ucommon::clear(), close(), EOF, ucommon::StreamBuffer::gbuf, GET, rd, and ucommon::fsys::read().

Member Data Documentation

◆ pid

shell::pid_t ucommon::pipestream::pid
protected

Definition at line 253 of file stream.h.

Referenced by close(), open(), and terminate().

◆ rd

fsys_t ucommon::pipestream::rd
protected

Definition at line 252 of file stream.h.

Referenced by open(), release(), and underflow().

◆ wr

fsys_t ucommon::pipestream::wr
protected

Definition at line 252 of file stream.h.

Referenced by open(), overflow(), and release().


The documentation for this class was generated from the following files: