Implement S/G IO for batched sends and eliminate another frame copy (#2874)

This commit is contained in:
Cameron Gutman
2024-07-18 23:04:18 -05:00
committed by GitHub
parent 16f62436a9
commit 3935d305ae
6 changed files with 199 additions and 56 deletions

View File

@@ -606,15 +606,60 @@ namespace platf {
void
restart();
struct batched_send_info_t {
struct buffer_descriptor_t {
const char *buffer;
size_t block_size;
size_t size;
// Constructors required for emplace_back() prior to C++20
buffer_descriptor_t(const char *buffer, size_t size):
buffer(buffer), size(size) {}
buffer_descriptor_t():
buffer(nullptr), size(0) {}
};
struct batched_send_info_t {
// Optional headers to be prepended to each packet
const char *headers;
size_t header_size;
// One or more data buffers to use for the payloads
//
// NB: Data buffers must be aligned to payload size!
std::vector<buffer_descriptor_t> &payload_buffers;
size_t payload_size;
// The offset (in header+payload message blocks) in the header and payload
// buffers to begin sending messages from
size_t block_offset;
// The number of header+payload message blocks to send
size_t block_count;
std::uintptr_t native_socket;
boost::asio::ip::address &target_address;
uint16_t target_port;
boost::asio::ip::address &source_address;
/**
* @brief Returns a payload buffer descriptor for the given payload offset.
* @param offset The offset in the total payload data (bytes).
* @return Buffer descriptor describing the region at the given offset.
*/
buffer_descriptor_t
buffer_for_payload_offset(ptrdiff_t offset) {
for (const auto &desc : payload_buffers) {
if (offset < desc.size) {
return {
desc.buffer + offset,
desc.size - offset,
};
}
else {
offset -= desc.size;
}
}
return {};
}
};
bool
send_batch(batched_send_info_t &send_info);