0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd::net: Add discard_all() convenience.

This commit is contained in:
Jason Volk 2018-01-11 18:38:29 -08:00
parent 37b98b5a82
commit 725f069621
2 changed files with 26 additions and 0 deletions

View file

@ -39,6 +39,9 @@ namespace ircd::net
// Alias to read_any(); // Alias to read_any();
size_t read(socket &, const vector_view<const mutable_buffer> &); size_t read(socket &, const vector_view<const mutable_buffer> &);
size_t read(socket &, const mutable_buffer &); size_t read(socket &, const mutable_buffer &);
// Yields until len has been discarded
size_t discard_all(socket &, const size_t &len);
} }
/// Alias to read_any(); /// Alias to read_any();

View file

@ -196,6 +196,29 @@ ircd::net::write_one(socket &socket,
// net/read.h // net/read.h
// //
/// Yields ircd::ctx until len bytes have been received and discarded from the
/// socket.
///
size_t
ircd::net::discard_all(socket &socket,
const size_t &len)
{
static char buffer[512] alignas(16);
size_t remain{len}; while(remain)
{
const mutable_buffer mb
{
buffer, std::min(remain, sizeof(buffer))
};
__builtin_prefetch(data(mb), 1, 0); // 1 = write, 0 = no cache
read_all(socket, mb);
}
return len;
}
/// Yields ircd::ctx until buffers are full. /// Yields ircd::ctx until buffers are full.
/// ///
/// Use this only if the following are true: /// Use this only if the following are true: