00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef SOCKETSTREAM_H
00016 #define SOCKETSTREAM_H
00017
00018 #include "pandabase.h"
00019 #include "trueClock.h"
00020 #include "config_express.h"
00021 #include "datagram.h"
00022 #include "pdeque.h"
00023 #include "typedReferenceCount.h"
00024 #include "pointerTo.h"
00025
00026
00027
00028
00029
00030 #ifdef HAVE_OPENSSL
00031
00032 class HTTPChannel;
00033
00034
00035
00036
00037
00038
00039
00040
00041 class EXPCL_PANDAEXPRESS SSReader {
00042 public:
00043 SSReader(istream *stream);
00044 virtual ~SSReader();
00045
00046 PUBLISHED:
00047 INLINE bool receive_datagram(Datagram &dg);
00048
00049 virtual bool is_closed() = 0;
00050 virtual void close() = 0;
00051
00052 INLINE void set_tcp_header_size(int tcp_header_size);
00053 INLINE int get_tcp_header_size() const;
00054
00055 private:
00056 bool do_receive_datagram(Datagram &dg);
00057
00058 istream *_istream;
00059 size_t _data_expected;
00060 string _data_so_far;
00061 int _tcp_header_size;
00062
00063 #ifdef SIMULATE_NETWORK_DELAY
00064 PUBLISHED:
00065 void start_delay(double min_delay, double max_delay);
00066 void stop_delay();
00067
00068 private:
00069 void delay_datagram(const Datagram &datagram);
00070 bool get_delayed(Datagram &datagram);
00071
00072 class DelayedDatagram {
00073 public:
00074 double _reveal_time;
00075 Datagram _datagram;
00076 };
00077
00078 typedef pdeque<DelayedDatagram> Delayed;
00079 Delayed _delayed;
00080 bool _delay_active;
00081 double _min_delay, _delay_variance;
00082
00083 #endif // SIMULATE_NETWORK_DELAY
00084 };
00085
00086
00087
00088
00089
00090
00091
00092
00093 class EXPCL_PANDAEXPRESS SSWriter {
00094 public:
00095 SSWriter(ostream *stream);
00096 virtual ~SSWriter();
00097
00098 PUBLISHED:
00099 bool send_datagram(const Datagram &dg);
00100
00101 virtual bool is_closed() = 0;
00102 virtual void close() = 0;
00103
00104 INLINE void set_collect_tcp(bool collect_tcp);
00105 INLINE bool get_collect_tcp() const;
00106 INLINE void set_collect_tcp_interval(double interval);
00107 INLINE double get_collect_tcp_interval() const;
00108
00109 INLINE void set_tcp_header_size(int tcp_header_size);
00110 INLINE int get_tcp_header_size() const;
00111
00112 INLINE bool consider_flush();
00113 INLINE bool flush();
00114
00115 private:
00116 ostream *_ostream;
00117 bool _collect_tcp;
00118 double _collect_tcp_interval;
00119 double _queued_data_start;
00120 int _tcp_header_size;
00121 };
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 class EXPCL_PANDAEXPRESS ISocketStream : public istream, public SSReader {
00133 public:
00134 INLINE ISocketStream(streambuf *buf);
00135 virtual ~ISocketStream();
00136
00137 PUBLISHED:
00138 enum ReadState {
00139 RS_initial,
00140 RS_reading,
00141 RS_complete,
00142 RS_error,
00143 };
00144
00145 virtual bool is_closed() = 0;
00146 virtual void close() = 0;
00147 virtual ReadState get_read_state() = 0;
00148
00149 protected:
00150 HTTPChannel *_channel;
00151
00152 private:
00153 friend class HTTPChannel;
00154 };
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 class EXPCL_PANDAEXPRESS OSocketStream : public ostream, public SSWriter {
00165 public:
00166 INLINE OSocketStream(streambuf *buf);
00167
00168 PUBLISHED:
00169 virtual bool is_closed() = 0;
00170 virtual void close() = 0;
00171
00172 INLINE bool flush();
00173 };
00174
00175
00176
00177
00178
00179
00180 class EXPCL_PANDAEXPRESS SocketStream : public iostream, public SSReader, public SSWriter {
00181 public:
00182 INLINE SocketStream(streambuf *buf);
00183
00184 PUBLISHED:
00185 virtual bool is_closed() = 0;
00186 virtual void close() = 0;
00187
00188 INLINE void set_tcp_header_size(int tcp_header_size);
00189 INLINE int get_tcp_header_size() const;
00190
00191 INLINE bool flush();
00192 };
00193
00194
00195 #include "socketStream.I"
00196
00197 #endif // HAVE_OPENSSL
00198
00199
00200 #endif
00201
00202