110 DBG(cerr <<
"In chunked_outbuf::end_chunk" << endl);
112 int32_t num = pptr() - pbase();
118 uint32_t header = (uint32_t)num | CHUNK_END;
122 if (!d_big_endian) header |= CHUNK_LITTLE_ENDIAN;
125 header = htonl(header);
130 d_os.write((
const char *)&header,
sizeof(uint32_t));
134 d_os.write(d_buffer, num);
135 if (d_os.eof() || d_os.bad())
136 return traits_type::eof();
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;
168 if (!d_big_endian) header |= CHUNK_LITTLE_ENDIAN;
171 header = htonl(header);
177 d_os.write((
const char *)&header,
sizeof(uint32_t));
181 d_os.write(msg.data(), msg.length());
182 if (d_os.eof() || d_os.bad())
183 return traits_type::eof();
249 DBG(cerr <<
"In chunked_outbuf::xsputn: num: " << num << endl);
259 int32_t bytes_in_buffer = pptr() - pbase();
264 if (bytes_in_buffer + num < d_buf_size) {
265 DBG2(cerr <<
":xsputn: buffering num: " << num << endl);
266 memcpy(pptr(), s, num);
268 return traits_type::not_eof(num);
273 uint32_t header = d_buf_size;
276 if (!d_big_endian) header |= CHUNK_LITTLE_ENDIAN;
279 header = htonl(header);
281 d_os.write((
const char *)&header,
sizeof(int32_t));
286 setp(d_buffer, d_buffer + (d_buf_size - 1));
288 d_os.write(d_buffer, bytes_in_buffer);
289 if (d_os.eof() || d_os.bad())
290 return traits_type::not_eof(0);
292 int bytes_to_fill_out_buffer = d_buf_size - bytes_in_buffer;
293 d_os.write(s, bytes_to_fill_out_buffer);
294 if (d_os.eof() || d_os.bad())
295 return traits_type::not_eof(0);
296 s += bytes_to_fill_out_buffer;
297 uint32_t bytes_still_to_send = num - bytes_to_fill_out_buffer;
301 while (bytes_still_to_send >= d_buf_size) {
303 d_os.write((
const char *) &header,
sizeof(int32_t));
304 d_os.write(s, d_buf_size);
305 if (d_os.eof() || d_os.bad())
return traits_type::not_eof(0);
307 bytes_still_to_send -= d_buf_size;
310 if (bytes_still_to_send > 0) {
314 memcpy(d_buffer, s, bytes_still_to_send);
315 pbump(bytes_still_to_send);
320 return traits_type::not_eof(num);