PLearn 0.1
Public Member Functions | Protected Member Functions | Protected Attributes | Private Types
PLearn::FdPStreamBuf Class Reference

#include <FdPStreamBuf.h>

Inheritance diagram for PLearn::FdPStreamBuf:
Inheritance graph
[legend]
Collaboration diagram for PLearn::FdPStreamBuf:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 FdPStreamBuf (int in_fd=-1, int out_fd=-1, bool own_in_=false, bool own_out_=false)
virtual ~FdPStreamBuf ()

Protected Member Functions

virtual streamsize read_ (char *p, streamsize n)
 reads up to n characters into p You should override this call in subclasses.
virtual void write_ (const char *p, streamsize n)
 writes exactly n characters from p (unbuffered, must flush)

Protected Attributes

int in
 input unix file descriptor (-1 if no input)
int out
 output unix file descriptor (-1 if no output)
bool own_in
bool own_out
 true if {pin|pout} should be closed by this object upon destruction.

Private Types

typedef PStreamBuf inherited

Detailed Description

Definition at line 54 of file FdPStreamBuf.h.


Member Typedef Documentation

Reimplemented from PLearn::PStreamBuf.

Definition at line 59 of file FdPStreamBuf.h.


Constructor & Destructor Documentation

PLearn::FdPStreamBuf::FdPStreamBuf ( int  in_fd = -1,
int  out_fd = -1,
bool  own_in_ = false,
bool  own_out_ = false 
)

Definition at line 76 of file FdPStreamBuf.cc.

    :PStreamBuf(in_fd>=0, out_fd>=0, 4096, 4096, default_ungetsize), 
     in(in_fd), out(out_fd), own_in(own_in_), own_out(own_out_)
{}
PLearn::FdPStreamBuf::~FdPStreamBuf ( ) [virtual]

Definition at line 82 of file FdPStreamBuf.cc.

References PLearn::PStreamBuf::flush(), in, out, own_in, and own_out.

{
    const bool in_and_out_equal = (in == out);

    flush();
    if(in>=0 && own_in)
    {
        ::close(in);
        in = -1;
    }
    if(out>=0 && own_out)
    {
        if (!in_and_out_equal)
            ::close(out);
        out = -1;
    }
}

Here is the call graph for this function:


Member Function Documentation

FdPStreamBuf::streamsize PLearn::FdPStreamBuf::read_ ( char *  p,
streamsize  n 
) [protected, virtual]

reads up to n characters into p You should override this call in subclasses.

Default version issues a PLERROR

On success, the number of bytes read is returned. Zero indicates end of file. If we are not at end of file, at least one character should be returned (the call must block until at least one char is available). It is not an error if the number returned is smaller than the number of bytes requested; this may happen for example because fewer bytes are actually available right now (maybe because we were close to end-of-file, or because we are reading from a pipe, or from a terminal). If an error occurs, an exception should be thrown.

Reimplemented from PLearn::PStreamBuf.

Definition at line 100 of file FdPStreamBuf.cc.

References in, and PLearn::PStreamBuf::read().

{
    return ::read(in, p, n);
}

Here is the call graph for this function:

void PLearn::FdPStreamBuf::write_ ( const char *  p,
streamsize  n 
) [protected, virtual]

writes exactly n characters from p (unbuffered, must flush)

Reimplemented from PLearn::PStreamBuf.

Definition at line 106 of file FdPStreamBuf.cc.

References n, out, PLERROR, and PLearn::PStreamBuf::write().

{
    streamsize nwritten = ::write(out, p, n);
    if(nwritten!=n)
        PLERROR("In FdPStreamBuf::write_ failed to write the requested number of bytes");
#ifdef _MINGW_
    PLERROR("In FdPStreamBuf::write_ - The 'fsync' function is not defined "
            "under MinGW (see code)");
#else
    fsync(out);
#endif
}

Here is the call graph for this function:


Member Data Documentation

input unix file descriptor (-1 if no input)

Definition at line 66 of file FdPStreamBuf.h.

Referenced by read_(), and ~FdPStreamBuf().

output unix file descriptor (-1 if no output)

Definition at line 67 of file FdPStreamBuf.h.

Referenced by write_(), and ~FdPStreamBuf().

Definition at line 68 of file FdPStreamBuf.h.

Referenced by ~FdPStreamBuf().

true if {pin|pout} should be closed by this object upon destruction.

Definition at line 68 of file FdPStreamBuf.h.

Referenced by ~FdPStreamBuf().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines