PLearn 0.1
|
An implementation of the PStreamBuf interface using Mozilla's NSPR library. More...
#include <PrPStreamBuf.h>
Public Member Functions | |
PrPStreamBuf (PRFileDesc *in=0, PRFileDesc *out=0, bool own_in_=false, bool own_out_=false) | |
virtual | ~PrPStreamBuf () |
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 | |
PRFileDesc * | in |
input NSPR file descriptor (0 if no input) | |
PRFileDesc * | out |
output NSPR file descriptor (0 if no output) | |
bool | own_in |
bool | own_out |
true if {in|out} should be closed by this object upon destruction. | |
Private Types | |
typedef PStreamBuf | inherited |
Friends | |
class | PLearn::Poll |
An implementation of the PStreamBuf interface using Mozilla's NSPR library.
Definition at line 58 of file PrPStreamBuf.h.
typedef PStreamBuf PLearn::PrPStreamBuf::inherited [private] |
Reimplemented from PLearn::PStreamBuf.
Definition at line 64 of file PrPStreamBuf.h.
PLearn::PrPStreamBuf::PrPStreamBuf | ( | PRFileDesc * | in = 0 , |
PRFileDesc * | out = 0 , |
||
bool | own_in_ = false , |
||
bool | own_out_ = false |
||
) |
Definition at line 53 of file PrPStreamBuf.cc.
: PStreamBuf(in_ != 0, out_ != 0, 4096, 4096, default_ungetsize), in(in_), out(out_), own_in(own_in_), own_out(own_out_) {}
PLearn::PrPStreamBuf::~PrPStreamBuf | ( | ) | [virtual] |
Definition at line 59 of file PrPStreamBuf.cc.
References PLearn::PStreamBuf::flush(), in, out, own_in, and own_out.
{ const bool in_and_out_equal = (in == out); try { flush(); } catch(...) { fprintf(stderr,"Could not properly clean up (flush) in destructor of PrPStreamBuf\n"); } if (in && own_in) { PR_Close(in); in = 0; } if (out && own_out) { // If "in" and "out" were pointing to the same PRFileDesc, // don't close it a second time. if (!in_and_out_equal) PR_Close(out); out = 0; } }
PrPStreamBuf::streamsize PLearn::PrPStreamBuf::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 85 of file PrPStreamBuf.cc.
References PLearn::getPrErrorString(), in, and PLERROR.
{ PRInt32 nr= PR_Read(in, p, PRInt32(n)); if(nr < 0) PLERROR((string("in PrPStreamBuf::read_ : no chars read: ") + getPrErrorString()).c_str()); return nr; }
void PLearn::PrPStreamBuf::write_ | ( | const char * | p, |
streamsize | n | ||
) | [protected, virtual] |
writes exactly n characters from p (unbuffered, must flush)
Reimplemented from PLearn::PStreamBuf.
Definition at line 94 of file PrPStreamBuf.cc.
friend class PLearn::Poll [friend] |
Definition at line 60 of file PrPStreamBuf.h.
PRFileDesc* PLearn::PrPStreamBuf::in [protected] |
input NSPR file descriptor (0 if no input)
Definition at line 71 of file PrPStreamBuf.h.
Referenced by read_(), PLearn::Poll::setStreamsToWatch(), and ~PrPStreamBuf().
PRFileDesc* PLearn::PrPStreamBuf::out [protected] |
output NSPR file descriptor (0 if no output)
Definition at line 72 of file PrPStreamBuf.h.
Referenced by write_(), and ~PrPStreamBuf().
bool PLearn::PrPStreamBuf::own_in [protected] |
Definition at line 73 of file PrPStreamBuf.h.
Referenced by ~PrPStreamBuf().
bool PLearn::PrPStreamBuf::own_out [protected] |
true if {in|out} should be closed by this object upon destruction.
Definition at line 73 of file PrPStreamBuf.h.
Referenced by ~PrPStreamBuf().