Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Examples  

sue_sess.hpp

Go to the documentation of this file.
00001 #ifndef SENTRY_SUE_SESS_HPP
00002 #define SENTRY_SUE_SESS_HPP
00003 
00004 
00005 #ifndef SENTRY_SUE_SEL_HPP
00006 #include "sue_sel.hpp"
00007 #endif
00008 
00009 
00011 class SUEBuffer {
00012     char *data;
00013     int datalen;
00014     int maxlen;
00015 public:
00017     SUEBuffer();
00019     ~SUEBuffer();
00020     
00022 
00023     void AddData(const char *buf, int size);
00024     
00026 
00033     int GetData(char *buf, int bufsize);
00034 
00036 
00039     void DropData(int len);
00040 
00042     void EraseData(int index, int len);
00043 
00045     void DropAll() { datalen = 0; } 
00046     
00048     void AddChar(char c);
00049 
00051 
00054     void AddString(const char *str);
00055 
00057 
00066     int ReadLine(char *buf, int bufsize);
00068 
00077     bool ReadLine(SUEBuffer &buf);
00078     
00080 
00081     int FindLineMarker(const char *marker) const;
00082     int ReadUntilLineMarker(const char *marker, char *buf, int bufsize);
00083     bool ReadUntilLineMarker(const char *marker, SUEBuffer &dest);
00084     
00086 
00089     bool ContainsExactText(const char *str) const;
00090     
00092 
00098     const char *GetBuffer() const { return data; }
00100 
00101     int Length() const { return datalen; }
00103 
00108     char& operator[](int i) const { return *(data + i); }
00109 
00110 private:
00111     void ProvideMaxLen(int n);
00112 };
00113 
00114 
00116 
00147 class SUEGenericDuplexSession : protected SUEFdHandler, 
00148                                 private SUETimeoutHandler 
00149 {
00150 
00151     long timeout_sec; 
00152     long timeout_usec; 
00153 
00155     bool scheduleddown; 
00156 
00157 protected: 
00158 
00160     SUEEventSelector *the_selector;
00161 
00163     SUEBuffer inputbuffer;
00165     SUEBuffer outputbuffer;
00166 
00167 
00169     bool inputresetstimeout;
00171     bool outputresetstimeout;
00172 
00174 
00183     virtual void FdHandle(bool a_r, bool a_w, bool a_ex);
00184 
00186 
00191     virtual void TimeoutHandle();
00192   
00193       
00195     virtual bool WantRead() const { return true; }
00199     virtual bool WantWrite() const { return outputbuffer.Length() > 0; }
00201     virtual bool WantExcept() const { return false; }
00202 
00203 public:
00205 
00212     SUEGenericDuplexSession(int a_timeout = 0,
00213                             const char *a_greeting = 0);    
00215     virtual ~SUEGenericDuplexSession();
00216 
00218 
00224     void SetTimeout(int sec, int usec = 0);
00225 
00227 
00234     void Startup(SUEEventSelector *a_selector, 
00235                  int a_fd, const char *a_greeting = 0);
00236 
00238 
00247     void Shutdown();
00248 
00250 
00253     void GracefulShutdown();
00254 
00256 
00264     virtual void HandleNewInput() = 0; 
00265 
00267 
00278     virtual void ShutdownHook() {} 
00279 
00281 
00285     virtual void HandleSessionTimeout() { Shutdown(); }
00286 
00288 
00292     virtual void HandleReadError() { Shutdown(); }
00293 
00295 
00299     virtual void HandleWriteError() { Shutdown(); }
00300 
00302 
00306     virtual void HandleRemoteClosing() { Shutdown(); }
00307 
00308 private:
00309     void ResetTimeout();
00310 };
00311 
00312 
00313 #endif //sentry

Generated on Fri Feb 27 13:17:25 2004 for SUE Library by doxygen1.2.18