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

panda/src/downloader/socketStream.h

Go to the documentation of this file.
00001 // Filename: socketStream.h
00002 // Created by:  drose (15Oct02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef SOCKETSTREAM_H
00020 #define SOCKETSTREAM_H
00021 
00022 #include "pandabase.h"
00023 #include "clockObject.h"
00024 #include "config_express.h" // for collect_tcp
00025 
00026 // At the present, this module is not compiled if OpenSSL is not
00027 // available, since the only current use for it is to implement
00028 // OpenSSL-defined constructs (like ISocketStream).
00029 
00030 #ifdef HAVE_SSL
00031 
00032 class Datagram;
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //       Class : ISocketStream
00036 // Description : This is a base class for istreams implemented in
00037 //               Panda that read from a (possibly non-blocking)
00038 //               socket.  It adds is_closed(), which can be called
00039 //               after an eof condition to check whether the socket
00040 //               has been closed, or whether more data may be
00041 //               available later.
00042 ////////////////////////////////////////////////////////////////////
00043 class EXPCL_PANDAEXPRESS ISocketStream : public istream {
00044 public:
00045   INLINE ISocketStream(streambuf *buf);
00046 
00047 PUBLISHED:
00048   bool receive_datagram(Datagram &dg);
00049 
00050   virtual bool is_closed() = 0;
00051 
00052 private:
00053   size_t _data_expected;
00054   string _data_so_far;
00055 };
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //       Class : OSocketStream
00059 // Description : A base class for ostreams that write to a (possibly
00060 //               non-blocking) socket.  It adds is_closed(), which can
00061 //               be called after any write operation fails to check
00062 //               whether the socket has been closed, or whether more
00063 //               data may be sent later.
00064 ////////////////////////////////////////////////////////////////////
00065 class EXPCL_PANDAEXPRESS OSocketStream : public ostream {
00066 public:
00067   INLINE OSocketStream(streambuf *buf);
00068 
00069 PUBLISHED:
00070   bool send_datagram(const Datagram &dg);
00071 
00072   virtual bool is_closed() = 0;
00073 
00074   INLINE void set_collect_tcp(bool collect_tcp);
00075   INLINE bool get_collect_tcp() const;
00076   INLINE void set_collect_tcp_interval(double interval);
00077   INLINE double get_collect_tcp_interval() const;
00078 
00079   INLINE bool consider_flush();
00080   INLINE bool flush();
00081 
00082 private:
00083   bool _collect_tcp;
00084   double _collect_tcp_interval;
00085   double _queued_data_start;
00086 };
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //       Class : SocketStream
00090 // Description : A base class for iostreams that read and write to a
00091 //               (possibly non-blocking) socket.
00092 ////////////////////////////////////////////////////////////////////
00093 class EXPCL_PANDAEXPRESS SocketStream : public iostream {
00094 public:
00095   INLINE SocketStream(streambuf *buf);
00096 
00097 PUBLISHED:
00098   bool receive_datagram(Datagram &dg);
00099   bool send_datagram(const Datagram &dg);
00100 
00101   virtual bool is_closed() = 0;
00102 
00103   INLINE void set_collect_tcp(bool collect_tcp);
00104   INLINE bool get_collect_tcp() const;
00105   INLINE void set_collect_tcp_interval(double interval);
00106   INLINE double get_collect_tcp_interval() const;
00107 
00108   INLINE bool consider_flush();
00109   INLINE bool flush();
00110 
00111 private:
00112   size_t _data_expected;
00113   string _data_so_far;
00114 
00115   bool _collect_tcp;
00116   double _collect_tcp_interval;
00117   double _queued_data_start;
00118 };
00119 
00120 
00121 #include "socketStream.I"
00122 
00123 #endif  // HAVE_SSL
00124 
00125 
00126 #endif
00127 
00128 

Generated on Fri May 2 00:36:52 2003 for Panda by doxygen1.3