-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Dear @xemul ,
I have a piece of code that constructs a scattered_message and passes this into the write() method of an output_stream<char>.
In particlar, I use the
void append_static (const char_type *buf, size_t size)method of scattered_message.
I am trying to port my code to Seastar's new API level 9, by constructing a vector of temporary_buffer<char>,
where for each buffer I use the zero-copy constructor:
temporary_buffer (CharType *buf, size_t size, deleter d) noexceptThe problem is that this takes a non-const pointer, which means I would need to use a const_cast when taking this route, which can, if I remember correctly, give Undefined Behavior, depending on the constness of the storage to which this pointer points.
In fact, I now see that scattered_message::append_static in fact does the same internally (via a C-style cast)
void append_static(const char_type* buf, size_t size) {
if (size) {
_p = packet(std::move(_p), fragment{(char_type*)buf, size}, deleter());
}
}Would you know of a way to support zero-copy-writes from storage pointed to by a const char* that avoids the need for a (possibly unsafe) const_cast ?