14 #ifndef SOCKETSTREAM_H
15 #define SOCKETSTREAM_H
39 class EXPCL_PANDA_DOWNLOADER SSReader {
41 SSReader(std::istream *stream);
45 INLINE
bool receive_datagram(
Datagram &dg);
47 virtual bool is_closed() = 0;
48 virtual void close() = 0;
50 INLINE
void set_tcp_header_size(
int tcp_header_size);
51 INLINE
int get_tcp_header_size()
const;
54 bool do_receive_datagram(
Datagram &dg);
56 std::istream *_istream;
57 size_t _data_expected;
58 vector_uchar _data_so_far;
61 #ifdef SIMULATE_NETWORK_DELAY
63 void start_delay(
double min_delay,
double max_delay);
67 void delay_datagram(
const Datagram &datagram);
68 bool get_delayed(
Datagram &datagram);
70 class DelayedDatagram {
79 double _min_delay, _delay_variance;
81 #endif // SIMULATE_NETWORK_DELAY
89 class EXPCL_PANDA_DOWNLOADER SSWriter {
91 SSWriter(std::ostream *stream);
95 bool send_datagram(
const Datagram &dg);
97 virtual bool is_closed() = 0;
98 virtual void close() = 0;
100 INLINE
void set_collect_tcp(
bool collect_tcp);
101 INLINE
bool get_collect_tcp()
const;
102 INLINE
void set_collect_tcp_interval(
double interval);
103 INLINE
double get_collect_tcp_interval()
const;
105 INLINE
void set_tcp_header_size(
int tcp_header_size);
106 INLINE
int get_tcp_header_size()
const;
108 INLINE
bool consider_flush();
112 std::ostream *_ostream;
114 double _collect_tcp_interval;
115 double _queued_data_start;
116 int _tcp_header_size;
125 class EXPCL_PANDA_DOWNLOADER ISocketStream :
public std::istream,
public SSReader {
127 INLINE ISocketStream(std::streambuf *buf);
128 virtual ~ISocketStream();
131 INLINE ISocketStream(
const ISocketStream ©) =
delete;
142 virtual bool is_closed() = 0;
143 virtual void close() = 0;
144 virtual ReadState get_read_state() = 0;
147 HTTPChannel *_channel;
150 friend class HTTPChannel;
159 class EXPCL_PANDA_DOWNLOADER OSocketStream :
public std::ostream,
public SSWriter {
161 INLINE OSocketStream(std::streambuf *buf);
164 INLINE OSocketStream(
const OSocketStream ©) =
delete;
168 virtual bool is_closed() = 0;
169 virtual void close() = 0;
178 class EXPCL_PANDA_DOWNLOADER SocketStream :
public std::iostream,
public SSReader,
public SSWriter {
180 INLINE SocketStream(std::streambuf *buf);
183 INLINE SocketStream(
const SocketStream ©) =
delete;
187 virtual bool is_closed() = 0;
188 virtual void close() = 0;
190 INLINE
void set_tcp_header_size(
int tcp_header_size);
191 INLINE
int get_tcp_header_size()
const;
199 #endif // HAVE_OPENSSL