41#include "chunked_ostream.h"
42#include "chunked_stream.h"
54 DBG(cerr <<
"In chunked_outbuf::data_chunk" << endl);
56 int32_t num = pptr() - pbase();
74 uint32_t header = num;
78 header |= CHUNK_LITTLE_ENDIAN;
81 header = htonl(header);
83 d_os.write((
const char *)&header,
sizeof(int32_t));
87 d_os.write(d_buffer, num);
88 if (d_os.eof() || d_os.bad())
89 return traits_type::eof();
107 DBG(cerr <<
"In chunked_outbuf::end_chunk" << endl);
109 int32_t num = pptr() - pbase();
115 uint32_t header = (uint32_t)num | CHUNK_END;
119 header |= CHUNK_LITTLE_ENDIAN;
122 header = htonl(header);
127 d_os.write((
const char *)&header,
sizeof(uint32_t));
131 d_os.write(d_buffer, num);
132 if (d_os.eof() || d_os.bad())
133 return traits_type::eof();
147 DBG(cerr <<
"In chunked_outbuf::err_chunk" << endl);
152 int32_t num = pptr() - pbase();
157 if (msg.length() > 0x00FFFFFF)
158 msg =
"Error message too long";
160 uint32_t header = (uint32_t)msg.length() | CHUNK_ERR;
164 header |= CHUNK_LITTLE_ENDIAN;
167 header = htonl(header);
172 d_os.write((
const char *)&header,
sizeof(uint32_t));
176 d_os.write(msg.data(), msg.length());
177 if (d_os.eof() || d_os.bad())
178 return traits_type::eof();
200 DBG(cerr <<
"In chunked_outbuf::overflow" << endl);
205 if (!traits_type::eq_int_type(c, traits_type::eof())) {
206 *pptr() = traits_type::not_eof(c);
212 return traits_type::eof();
215 return traits_type::not_eof(c);
240 DBG(cerr <<
"In chunked_outbuf::xsputn: num: " << num << endl);
250 int32_t bytes_in_buffer = pptr() - pbase();
255 if (bytes_in_buffer + num < d_buf_size) {
256 DBG2(cerr <<
":xsputn: buffering num: " << num << endl);
257 memcpy(pptr(), s, num);
259 return traits_type::not_eof(num);
264 uint32_t header = d_buf_size;
268 header |= CHUNK_LITTLE_ENDIAN;
271 header = htonl(header);
273 d_os.write((
const char *)&header,
sizeof(int32_t));
278 setp(d_buffer, d_buffer + (d_buf_size - 1));
280 d_os.write(d_buffer, bytes_in_buffer);
281 if (d_os.eof() || d_os.bad())
282 return traits_type::not_eof(0);
284 int bytes_to_fill_out_buffer = d_buf_size - bytes_in_buffer;
285 d_os.write(s, bytes_to_fill_out_buffer);
286 if (d_os.eof() || d_os.bad())
287 return traits_type::not_eof(0);
288 s += bytes_to_fill_out_buffer;
289 uint32_t bytes_still_to_send = num - bytes_to_fill_out_buffer;
293 while (bytes_still_to_send >= d_buf_size) {
295 d_os.write((
const char *)&header,
sizeof(int32_t));
296 d_os.write(s, d_buf_size);
297 if (d_os.eof() || d_os.bad())
298 return traits_type::not_eof(0);
300 bytes_still_to_send -= d_buf_size;
303 if (bytes_still_to_send > 0) {
307 memcpy(d_buffer, s, bytes_still_to_send);
308 pbump(bytes_still_to_send);
313 return traits_type::not_eof(num);
322 DBG(cerr <<
"In chunked_outbuf::sync" << endl);
326 return traits_type::not_eof(-1);
328 return traits_type::not_eof(0);
virtual std::streamsize xsputn(const char *s, std::streamsize num)
Write bytes to the chunked stream Write the bytes in s to the chunked stream.
int_type end_chunk()
Send an end chunk.
int_type data_chunk()
Write out the contents of the buffer as a chunk.
int_type err_chunk(const std::string &msg)
Send an error chunk While building up the next chunk, send an error chunk, ignoring the data currentl...
virtual int_type sync()
Synchronize the stream with its data sink.
virtual int_type overflow(int c)
Virtual method called when the internal buffer would overflow. When the internal buffer fills,...
top level DAP object to house generic methods