0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 08:13:46 +02:00

ircd::net: Add tools to query socket write buffering related.

This commit is contained in:
Jason Volk 2020-12-24 06:56:20 -08:00
parent 7e81806f29
commit f30c5f381b
2 changed files with 42 additions and 0 deletions

View file

@ -15,6 +15,10 @@ namespace ircd::net
{
using const_buffers = vector_view<const const_buffer>;
// Observers
size_t flushing(const socket &);
size_t writable(const socket &);
// Non-blocking; writes at most one system-determined amount of
// bytes or less with at most a single syscall.
size_t write_one(socket &, const const_buffers &);

View file

@ -331,6 +331,44 @@ ircd::net::write_one(socket &socket,
return socket.write_one(buffers);
}
/// Bytes remaining for transmission (in the kernel)
size_t
ircd::net::writable(const socket &socket)
{
const ssize_t write_bufsz
(
net::write_bufsz(socket)
);
const ssize_t flushing
(
net::flushing(socket)
);
assert(write_bufsz >= flushing);
return std::max(write_bufsz - flushing, 0L);
}
/// Bytes buffered for transmission (in the kernel)
size_t
ircd::net::flushing(const socket &socket)
{
const ip::tcp::socket &sd(socket);
const auto &fd
{
mutable_cast(sd).lowest_layer().native_handle()
};
long value(0);
#ifdef TIOCOUTQ
syscall(::ioctl, fd, TIOCOUTQ, &value);
#else
#warning "TIOCOUTQ is not defined on this platform."
#endif
return value;
}
///////////////////////////////////////////////////////////////////////////////
//
// net/read.h