30 #include <arpa/inet.h>
53 std::streambuf::int_type
56 DBG(cerr <<
"In chunked_outbuf::data_chunk" << endl);
58 int32_t num = pptr() - pbase();
76 uint32_t header = num;
77 #if !BYTE_ORDER_PREFIX
84 d_os.write((
const char *)&header,
sizeof(int32_t));
90 return traits_type::eof();
107 std::streambuf::int_type
110 DBG(cerr <<
"In chunked_outbuf::end_chunk" << endl);
112 int32_t num = pptr() - pbase();
118 uint32_t header = (uint32_t)num |
CHUNK_END;
120 #if !BYTE_ORDER_PREFIX
130 d_os.write((
const char *)&header,
sizeof(uint32_t));
136 return traits_type::eof();
149 std::streambuf::int_type
152 DBG(cerr <<
"In chunked_outbuf::err_chunk" << endl);
157 int32_t num = pptr() - pbase();
162 if (msg.length() > 0x00FFFFFF)
163 msg =
"Error message too long";
165 uint32_t header = (uint32_t)msg.length() |
CHUNK_ERR;
167 #if !BYTE_ORDER_PREFIX
177 d_os.write((
const char *)&header,
sizeof(uint32_t));
181 d_os.write(msg.data(), msg.length());
183 return traits_type::eof();
204 std::streambuf::int_type
207 DBG(cerr <<
"In chunked_outbuf::overflow" << endl);
212 if (!traits_type::eq_int_type(c, traits_type::eof())) {
213 *pptr() = traits_type::not_eof(c);
219 return traits_type::eof();
222 return traits_type::not_eof(c);
249 DBG(cerr <<
"In chunked_outbuf::xsputn: num: " << num << endl);
259 int32_t bytes_in_buffer = pptr() - pbase();
265 DBG2(cerr <<
":xsputn: buffering num: " << num << endl);
266 memcpy(pptr(), s, num);
268 return traits_type::not_eof(num);
274 #if !BYTE_ORDER_PREFIX
280 d_os.write((
const char *)&header,
sizeof(int32_t));
289 return traits_type::not_eof(0);
291 int bytes_to_fill_out_buffer =
d_buf_size - bytes_in_buffer;
292 d_os.write(s, bytes_to_fill_out_buffer);
294 return traits_type::not_eof(0);
295 s += bytes_to_fill_out_buffer;
296 uint32_t bytes_still_to_send = num - bytes_to_fill_out_buffer;
302 d_os.write((
const char *) &header,
sizeof(int32_t));
304 if (
d_os.eof() ||
d_os.bad())
return traits_type::not_eof(0);
309 if (bytes_still_to_send > 0) {
313 memcpy(
d_buffer, s, bytes_still_to_send);
314 pbump(bytes_still_to_send);
319 return traits_type::not_eof(num);
327 std::streambuf::int_type
330 DBG(cerr <<
"In chunked_outbuf::sync" << endl);
334 return traits_type::not_eof(-1);
336 return traits_type::not_eof(0);
virtual int_type overflow(int c)
Virtual method called when the internal buffer would overflow. When the internal buffer fills...
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 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.
int_type data_chunk()
Write out the contents of the buffer as a chunk.
#define CHUNK_LITTLE_ENDIAN