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();
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);