mirror of
https://github.com/matrix-construct/construct
synced 2025-01-23 04:50:00 +01:00
ircd::net: Consolidate SSL_pending related behind interface.
This commit is contained in:
parent
ee31b5a59f
commit
eca02723b3
3 changed files with 26 additions and 42 deletions
|
@ -16,8 +16,9 @@ namespace ircd::net
|
||||||
using mutable_buffers = vector_view<const mutable_buffer>;
|
using mutable_buffers = vector_view<const mutable_buffer>;
|
||||||
|
|
||||||
// Observers
|
// Observers
|
||||||
size_t readable(const socket &);
|
size_t readable(const socket &); // don't use w/ ssl
|
||||||
size_t available(const socket &) noexcept;
|
size_t available(const socket &) noexcept; // don't use w/ ssl
|
||||||
|
size_t pending(const socket &) noexcept; // use with either.
|
||||||
|
|
||||||
// Non-blocking; read into buffers in a single syscall
|
// Non-blocking; read into buffers in a single syscall
|
||||||
size_t read_one(socket &, const mutable_buffers &);
|
size_t read_one(socket &, const mutable_buffers &);
|
||||||
|
|
33
ircd/net.cc
33
ircd/net.cc
|
@ -488,6 +488,22 @@ ircd::net::read_one(socket &socket,
|
||||||
return socket.read_one(buffers);
|
return socket.read_one(buffers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Bytes available for reading (SSL; w/ fallback).
|
||||||
|
/// @returns 0 for socket errors, unsupported, or nothing available.
|
||||||
|
size_t
|
||||||
|
ircd::net::pending(const socket &socket)
|
||||||
|
noexcept
|
||||||
|
{
|
||||||
|
if(!socket.ssl)
|
||||||
|
return available(socket);
|
||||||
|
|
||||||
|
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||||
|
return SSL_pending(mutable_cast(socket).ssl->native_handle());
|
||||||
|
#else
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/// Bytes available for reading (userspace)
|
/// Bytes available for reading (userspace)
|
||||||
size_t
|
size_t
|
||||||
ircd::net::available(const socket &socket)
|
ircd::net::available(const socket &socket)
|
||||||
|
@ -2240,28 +2256,15 @@ noexcept try
|
||||||
|
|
||||||
if constexpr((false)) // manual debug; large nr syscalls
|
if constexpr((false)) // manual debug; large nr syscalls
|
||||||
{
|
{
|
||||||
const auto has_pending
|
|
||||||
{
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x1010000L
|
|
||||||
ssl?
|
|
||||||
SSL_has_pending(ssl->native_handle()):
|
|
||||||
0
|
|
||||||
#else
|
|
||||||
0
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
char ecbuf[64];
|
char ecbuf[64];
|
||||||
log::debug
|
log::debug
|
||||||
{
|
{
|
||||||
log, "%s ready %s %s avail:%zu:%zu:%d:%d",
|
log, "%s ready %s %s avail:%zu:%zu",
|
||||||
loghead(*this),
|
loghead(*this),
|
||||||
reflect(type),
|
reflect(type),
|
||||||
string(ecbuf, ec),
|
string(ecbuf, ec),
|
||||||
type == ready::READ? bytes : 0UL,
|
type == ready::READ? bytes : 0UL,
|
||||||
type == ready::READ? available(*this) : 0UL,
|
type == ready::READ? pending(*this): 0UL,
|
||||||
has_pending,
|
|
||||||
ssl? SSL_pending(ssl->native_handle()): 0,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2902,45 +2902,25 @@ void
|
||||||
ircd::server::link::discard_read()
|
ircd::server::link::discard_read()
|
||||||
{
|
{
|
||||||
assert(socket);
|
assert(socket);
|
||||||
const size_t available
|
const size_t pending
|
||||||
{
|
{
|
||||||
net::available(*socket)
|
net::pending(*socket)
|
||||||
};
|
|
||||||
|
|
||||||
const ssize_t has_pending
|
|
||||||
{
|
|
||||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)
|
|
||||||
socket->ssl?
|
|
||||||
SSL_has_pending(socket->ssl->native_handle()):
|
|
||||||
-2L
|
|
||||||
#else
|
|
||||||
-2L
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
const ssize_t pending
|
|
||||||
{
|
|
||||||
socket->ssl?
|
|
||||||
SSL_pending(socket->ssl->native_handle()):
|
|
||||||
0L
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const size_t discarded
|
const size_t discarded
|
||||||
{
|
{
|
||||||
discard_any(*socket, size_t(pending))
|
discard_any(*socket, pending)
|
||||||
};
|
};
|
||||||
|
|
||||||
if(discarded)
|
if(discarded)
|
||||||
{
|
{
|
||||||
log::dwarning
|
log::dwarning
|
||||||
{
|
{
|
||||||
log, "%s q:%zu discarded:%zu pending:%zd has_pending:%zd available:%zd",
|
log, "%s q:%zu pending:%zu discarded:%zu",
|
||||||
loghead(*this),
|
loghead(*this),
|
||||||
queue.size(),
|
queue.size(),
|
||||||
discarded,
|
|
||||||
pending,
|
pending,
|
||||||
has_pending,
|
discarded,
|
||||||
available,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
assert(peer);
|
assert(peer);
|
||||||
|
|
Loading…
Add table
Reference in a new issue