mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd::net: Add discard_all() convenience.
This commit is contained in:
parent
37b98b5a82
commit
725f069621
2 changed files with 26 additions and 0 deletions
|
@ -39,6 +39,9 @@ namespace ircd::net
|
|||
// Alias to read_any();
|
||||
size_t read(socket &, const vector_view<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();
|
||||
|
|
23
ircd/net.cc
23
ircd/net.cc
|
@ -196,6 +196,29 @@ ircd::net::write_one(socket &socket,
|
|||
// 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.
|
||||
///
|
||||
/// Use this only if the following are true:
|
||||
|
|
Loading…
Reference in a new issue