hdr.flags = htonl(0);
iovec iov;
- iov.iov_base = new char[sizeof(hdr)];
+ iov.iov_base = new char[bytes + sizeof(hdr)];
+ iov.iov_len = bytes + sizeof(hdr);
+
memcpy(iov.iov_base, &hdr, sizeof(hdr));
- iov.iov_len = sizeof(hdr);
+ memcpy(reinterpret_cast<char *>(iov.iov_base) + sizeof(hdr), data, bytes);
+
+ queued_data.push_back(iov);
+ } else if (encoding == Stream::STREAM_ENCODING_RAW) {
+ // Just add the data itself.
+ iovec iov;
+ iov.iov_base = new char[bytes];
+ memcpy(iov.iov_base, data, bytes);
+ iov.iov_len = bytes;
+
queued_data.push_back(iov);
} else {
assert(encoding == Stream::STREAM_ENCODING_RAW);