From 08d39efca66b92046511ac284e89749ab4fea3dd Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 1 Jul 2022 13:36:04 -0700 Subject: [PATCH] ircd::net: Fix double-jumps through interface glues; internalize symbols. --- include/ircd/net/dns_resolver.h | 4 +- include/ircd/net/socket.h | 16 ++++---- ircd/net.cc | 67 +++++++++++++++++---------------- 3 files changed, 44 insertions(+), 43 deletions(-) diff --git a/include/ircd/net/dns_resolver.h b/include/ircd/net/dns_resolver.h index 5e966d28a..7e8dfae45 100644 --- a/include/ircd/net/dns_resolver.h +++ b/include/ircd/net/dns_resolver.h @@ -27,7 +27,7 @@ namespace ircd::net::dns uint16_t resolver_call(const hostport &, const opts &); } -struct [[gnu::visibility("protected")]] +struct [[gnu::visibility("hidden")]] ircd::net::dns::resolver { using header = rfc1035::header; @@ -101,7 +101,7 @@ ircd::net::dns::resolver ~resolver() noexcept; }; -struct [[gnu::visibility("protected")]] +struct [[gnu::visibility("hidden")]] ircd::net::dns::tag { uint16_t id {0}; diff --git a/include/ircd/net/socket.h b/include/ircd/net/socket.h index 70e0de833..0a8ffc8bc 100644 --- a/include/ircd/net/socket.h +++ b/include/ircd/net/socket.h @@ -94,16 +94,16 @@ ircd::net::socket milliseconds cancel_timeout() noexcept; // low level write suite - template size_t write_one(iov&&); // non-blocking - template size_t write_any(iov&&); // non-blocking - template size_t write_few(iov&&); // yielding - template size_t write_all(iov&&); // yielding + size_t write_one(const const_buffers &); // non-blocking + size_t write_any(const const_buffers &); // non-blocking + size_t write_few(const const_buffers &); // yielding + size_t write_all(const const_buffers &); // yielding // low level read suite - template size_t read_one(iov&&); // non-blocking - template size_t read_any(iov&&); // non-blocking - template size_t read_few(iov&&); // yielding - template size_t read_all(iov&&); // yielding + size_t read_one(const mutable_buffers &); // non-blocking + size_t read_any(const mutable_buffers &); // non-blocking + size_t read_few(const mutable_buffers &); // yielding + size_t read_all(const mutable_buffers &); // yielding // low level check suite error_code check(std::nothrow_t, const ready &) noexcept; diff --git a/ircd/net.cc b/ircd/net.cc index 211904dfb..d474db553 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -1689,7 +1689,8 @@ catch(const boost::system::system_error &e) throw_system_error(e); } -std::error_code +[[gnu::always_inline]] +inline std::error_code ircd::net::socket::check(std::nothrow_t, const ready &type) noexcept @@ -1730,9 +1731,9 @@ noexcept } /// Yields ircd::ctx until buffers are full. -template -size_t -ircd::net::socket::read_all(iov&& bufs) +[[gnu::always_inline]] +inline size_t +ircd::net::socket::read_all(const mutable_buffers &bufs) try { static const auto completion @@ -1752,7 +1753,7 @@ try continuation::asio_predicate, interruption, [this, &ret, &bufs] (auto &yield) { - ret = asio::async_read(ssl, std::forward(bufs), completion, yield); + ret = asio::async_read(ssl, bufs, completion, yield); } }; @@ -1774,9 +1775,9 @@ catch(const boost::system::system_error &e) } /// Yields ircd::ctx until remote has sent at least some data. -template -size_t -ircd::net::socket::read_few(iov&& bufs) +[[gnu::always_inline]] +inline size_t +ircd::net::socket::read_few(const mutable_buffers &bufs) try { assert(!fini); @@ -1791,7 +1792,7 @@ try continuation::asio_predicate, interruption, [this, &ret, &bufs] (auto &yield) { - ret = ssl.async_read_some(std::forward(bufs), yield); + ret = ssl.async_read_some(bufs, yield); } }; @@ -1813,9 +1814,9 @@ catch(const boost::system::system_error &e) } /// Non-blocking; as much as possible without blocking -template -size_t -ircd::net::socket::read_any(iov&& bufs) +[[gnu::always_inline]] +inline size_t +ircd::net::socket::read_any(const mutable_buffers &bufs) { static const auto completion { @@ -1827,7 +1828,7 @@ ircd::net::socket::read_any(iov&& bufs) boost::system::error_code ec; const size_t ret { - asio::read(ssl, std::forward(bufs), completion, ec) + asio::read(ssl, bufs, completion, ec) }; ++in.calls; @@ -1846,16 +1847,16 @@ ircd::net::socket::read_any(iov&& bufs) } /// Non-blocking; One system call only; never throws eof; -template -size_t -ircd::net::socket::read_one(iov&& bufs) +[[gnu::always_inline]] +inline size_t +ircd::net::socket::read_one(const mutable_buffers &bufs) { assert(!fini); assert(!blocking(*this)); boost::system::error_code ec; const size_t ret { - ssl.read_some(std::forward(bufs), ec) + ssl.read_some(bufs, ec) }; ++in.calls; @@ -1874,9 +1875,9 @@ ircd::net::socket::read_one(iov&& bufs) } /// Yields ircd::ctx until all buffers are sent. -template -size_t -ircd::net::socket::write_all(iov&& bufs) +[[gnu::always_inline]] +inline size_t +ircd::net::socket::write_all(const const_buffers &bufs) try { static const auto completion @@ -1897,7 +1898,7 @@ try continuation::asio_predicate, interruption, [this, &ret, &bufs] (auto &yield) { - ret = asio::async_write(ssl, std::forward(bufs), completion, yield); + ret = asio::async_write(ssl, bufs, completion, yield); } }; @@ -1913,9 +1914,9 @@ catch(const boost::system::system_error &e) } /// Yields ircd::ctx until one or more bytes are sent. -template -size_t -ircd::net::socket::write_few(iov&& bufs) +[[gnu::always_inline]] +inline size_t +ircd::net::socket::write_few(const const_buffers &bufs) try { assert(!fini); @@ -1931,7 +1932,7 @@ try continuation::asio_predicate, interruption, [this, &ret, &bufs] (auto &yield) { - ret = ssl.async_write_some(std::forward(bufs), yield); + ret = ssl.async_write_some(bufs, yield); } }; @@ -1947,9 +1948,9 @@ catch(const boost::system::system_error &e) } /// Non-blocking; writes as much as possible without blocking -template -size_t -ircd::net::socket::write_any(iov&& bufs) +[[gnu::always_inline]] +inline size_t +ircd::net::socket::write_any(const const_buffers &bufs) try { static const auto completion @@ -1961,7 +1962,7 @@ try assert(!blocking(*this)); const size_t ret { - asio::write(ssl, std::forward(bufs), completion) + asio::write(ssl, bufs, completion) }; ++out.calls; @@ -1976,16 +1977,16 @@ catch(const boost::system::system_error &e) } /// Non-blocking; Writes one "unit" of data or less; never more. -template -size_t -ircd::net::socket::write_one(iov&& bufs) +[[gnu::always_inline]] +inline size_t +ircd::net::socket::write_one(const const_buffers &bufs) try { assert(!fini); assert(!blocking(*this)); const size_t ret { - ssl.write_some(std::forward(bufs)) + ssl.write_some(bufs) }; ++out.calls;