CCAFFEINE  0.8.8
NonblockingReader.h
00001 #ifndef __NONBLOCKINGREADER_H__
00002 #define __NONBLOCKINGREADER_H__
00003 
00004 namespace jcpp {
00005 
00006 // Depends on:
00007 /* #include <sys/time.h> */
00008 /* #include <error.h> */
00009 /* #include <sys/types.h> */
00010 /* #include <unistd.h> */
00011 /* #include <assert.h> */
00012 /* #include "jc++/jc++.h" */
00013 /* #include "jc++/util/jc++util.h" */
00014 /* #include "util/IO.h" */
00015 /* #include "Reader.h" */
00016 
00020 class NonblockingReader : public virtual Reader {
00021  private:
00022 
00023   CDELETE Reader* in;
00024 
00025   char* cb;
00026   char* tmp;
00027   int nChars; 
00028   int nextChar; 
00029   int maxChars; 
00030   int incrChars; 
00031   int defaultCharBufferSize;
00032   int defaultExpectedLineLength;
00033 
00037   void compactBuffer();
00040   boolean fillNonblocking();
00044   void expandBufferMemory();
00045 
00046  public:
00047 
00048   NonblockingReader(Reader* in);
00049   virtual ~NonblockingReader();
00051   virtual void close() {
00052     in->close();
00053   }
00055   virtual void mark() {
00056     en((char *)"not allowed to use mark() in Reader");
00057   }
00059   virtual boolean markSupported() {
00060     return FALSE;
00061   }
00063   virtual int read();
00065   virtual int read(char* cbuf, int length) {
00066     return read(cbuf, 0 , length);
00067   }
00068 
00069  private:
00070 
00074   int preRead(char* cbuf, int off, int length);
00077   int nonblockingRead(char* cbuf, int off, int length);
00078 
00079  public:
00080 
00084   virtual int read(char* cbuf, int off, int length);
00086   virtual boolean ready() {
00087     return (nextChar < nChars) || in->ready();
00088   }
00091   virtual void reset() {
00092     en((char *)":-( Reader::reset() not supported");
00093   }
00095   virtual long skip(long length);
00099   virtual CFREE char* readLine();
00100  private:
00101 
00102   int findLineInBuffer();
00103 
00104 };
00105 
00106 } ENDSEMI // jcpp
00107 
00108 
00109 
00110 #endif // __NONBLOCKINGREADER_H__