From 4aef8cfdf80a677053829c56dc99dfeb862cac1a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 3 May 2019 16:28:00 -0700 Subject: [PATCH] ircd::net::socket: Deinline the read/write member template suites. --- include/ircd/net/socket.h | 245 -------------------------------------- ircd/net.cc | 245 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 245 insertions(+), 245 deletions(-) diff --git a/include/ircd/net/socket.h b/include/ircd/net/socket.h index 8440face4..50aa5b29f 100644 --- a/include/ircd/net/socket.h +++ b/include/ircd/net/socket.h @@ -129,248 +129,3 @@ ircd::net::socket::operator()(args&&... a) { return this->wait(std::forward(a)...); } - -/// Yields ircd::ctx until buffers are full. -template -size_t -ircd::net::socket::read_all(iov&& bufs) -try -{ - static const auto completion - { - asio::transfer_all() - }; - - const auto interruption{[this] - (ctx::ctx *const &) - { - this->cancel(); - }}; - - size_t ret; continuation - { - continuation::asio_predicate, interruption, [this, &ret, &bufs] - (auto &yield) - { - ret = asio::async_read(ssl, std::forward(bufs), completion, yield); - } - }; - - if(!ret) - throw std::system_error - { - boost::asio::error::eof, boost::asio::error::get_misc_category() - }; - - in.bytes += ret; - ++in.calls; - return ret; -} -catch(const boost::system::system_error &e) -{ - throw_system_error(e); -} - -/// Yields ircd::ctx until remote has sent at least some data. -template -size_t -ircd::net::socket::read_few(iov&& bufs) -try -{ - const auto interruption{[this] - (ctx::ctx *const &) - { - this->cancel(); - }}; - - size_t ret; continuation - { - continuation::asio_predicate, interruption, [this, &ret, &bufs] - (auto &yield) - { - ret = ssl.async_read_some(std::forward(bufs), yield); - } - }; - - if(!ret) - throw std::system_error - { - asio::error::eof, asio::error::get_misc_category() - }; - - in.bytes += ret; - ++in.calls; - return ret; -} -catch(const boost::system::system_error &e) -{ - throw_system_error(e); -} - -/// Non-blocking; as much as possible without blocking -template -size_t -ircd::net::socket::read_any(iov&& bufs) -{ - assert(!blocking(*this)); - static const auto completion - { - asio::transfer_all() - }; - - boost::system::error_code ec; - const size_t ret - { - asio::read(ssl, std::forward(bufs), completion, ec) - }; - - in.bytes += ret; - ++in.calls; - - if(likely(!ec)) - return ret; - - if(ec == boost::system::errc::resource_unavailable_try_again) - return ret; - - throw_system_error(ec); - __builtin_unreachable(); -} - -/// Non-blocking; One system call only; never throws eof; -template -size_t -ircd::net::socket::read_one(iov&& bufs) -{ - assert(!blocking(*this)); - - boost::system::error_code ec; - const size_t ret - { - ssl.read_some(std::forward(bufs), ec) - }; - - in.bytes += ret; - ++in.calls; - - if(likely(!ec)) - return ret; - - if(ec == boost::system::errc::resource_unavailable_try_again) - return ret; - - throw_system_error(ec); - __builtin_unreachable(); -} - -/// Yields ircd::ctx until all buffers are sent. -template -size_t -ircd::net::socket::write_all(iov&& bufs) -try -{ - static const auto completion - { - asio::transfer_all() - }; - - const auto interruption{[this] - (ctx::ctx *const &) - { - this->cancel(); - }}; - - size_t ret; continuation - { - continuation::asio_predicate, interruption, [this, &ret, &bufs] - (auto &yield) - { - ret = asio::async_write(ssl, std::forward(bufs), completion, yield); - } - }; - - out.bytes += ret; - ++out.calls; - return ret; -} -catch(const boost::system::system_error &e) -{ - throw_system_error(e); -} - -/// Yields ircd::ctx until one or more bytes are sent. -template -size_t -ircd::net::socket::write_few(iov&& bufs) -try -{ - const auto interruption{[this] - (ctx::ctx *const &) - { - this->cancel(); - }}; - - size_t ret; continuation - { - continuation::asio_predicate, interruption, [this, &ret, &bufs] - (auto &yield) - { - ret = ssl.async_write_some(std::forward(bufs), yield); - } - }; - - out.bytes += ret; - ++out.calls; - return ret; -} -catch(const boost::system::system_error &e) -{ - throw_system_error(e); -} - -/// Non-blocking; writes as much as possible without blocking -template -size_t -ircd::net::socket::write_any(iov&& bufs) -try -{ - static const auto completion - { - asio::transfer_all() - }; - - assert(!blocking(*this)); - const size_t ret - { - asio::write(ssl, std::forward(bufs), completion) - }; - - out.bytes += ret; - ++out.calls; - return ret; -} -catch(const boost::system::system_error &e) -{ - throw_system_error(e); -} - -/// Non-blocking; Writes one "unit" of data or less; never more. -template -size_t -ircd::net::socket::write_one(iov&& bufs) -try -{ - assert(!blocking(*this)); - const size_t ret - { - ssl.write_some(std::forward(bufs)) - }; - - out.bytes += ret; - ++out.calls; - return ret; -} -catch(const boost::system::system_error &e) -{ - throw_system_error(e); -} diff --git a/ircd/net.cc b/ircd/net.cc index e1e3f784b..c691f53de 100644 --- a/ircd/net.cc +++ b/ircd/net.cc @@ -2929,6 +2929,251 @@ noexcept return ret; } +/// Yields ircd::ctx until buffers are full. +template +size_t +ircd::net::socket::read_all(iov&& bufs) +try +{ + static const auto completion + { + asio::transfer_all() + }; + + const auto interruption{[this] + (ctx::ctx *const &) + { + this->cancel(); + }}; + + size_t ret; continuation + { + continuation::asio_predicate, interruption, [this, &ret, &bufs] + (auto &yield) + { + ret = asio::async_read(ssl, std::forward(bufs), completion, yield); + } + }; + + if(!ret) + throw std::system_error + { + boost::asio::error::eof, boost::asio::error::get_misc_category() + }; + + in.bytes += ret; + ++in.calls; + return ret; +} +catch(const boost::system::system_error &e) +{ + throw_system_error(e); +} + +/// Yields ircd::ctx until remote has sent at least some data. +template +size_t +ircd::net::socket::read_few(iov&& bufs) +try +{ + const auto interruption{[this] + (ctx::ctx *const &) + { + this->cancel(); + }}; + + size_t ret; continuation + { + continuation::asio_predicate, interruption, [this, &ret, &bufs] + (auto &yield) + { + ret = ssl.async_read_some(std::forward(bufs), yield); + } + }; + + if(!ret) + throw std::system_error + { + asio::error::eof, asio::error::get_misc_category() + }; + + in.bytes += ret; + ++in.calls; + return ret; +} +catch(const boost::system::system_error &e) +{ + throw_system_error(e); +} + +/// Non-blocking; as much as possible without blocking +template +size_t +ircd::net::socket::read_any(iov&& bufs) +{ + assert(!blocking(*this)); + static const auto completion + { + asio::transfer_all() + }; + + boost::system::error_code ec; + const size_t ret + { + asio::read(ssl, std::forward(bufs), completion, ec) + }; + + in.bytes += ret; + ++in.calls; + + if(likely(!ec)) + return ret; + + if(ec == boost::system::errc::resource_unavailable_try_again) + return ret; + + throw_system_error(ec); + __builtin_unreachable(); +} + +/// Non-blocking; One system call only; never throws eof; +template +size_t +ircd::net::socket::read_one(iov&& bufs) +{ + assert(!blocking(*this)); + + boost::system::error_code ec; + const size_t ret + { + ssl.read_some(std::forward(bufs), ec) + }; + + in.bytes += ret; + ++in.calls; + + if(likely(!ec)) + return ret; + + if(ec == boost::system::errc::resource_unavailable_try_again) + return ret; + + throw_system_error(ec); + __builtin_unreachable(); +} + +/// Yields ircd::ctx until all buffers are sent. +template +size_t +ircd::net::socket::write_all(iov&& bufs) +try +{ + static const auto completion + { + asio::transfer_all() + }; + + const auto interruption{[this] + (ctx::ctx *const &) + { + this->cancel(); + }}; + + size_t ret; continuation + { + continuation::asio_predicate, interruption, [this, &ret, &bufs] + (auto &yield) + { + ret = asio::async_write(ssl, std::forward(bufs), completion, yield); + } + }; + + out.bytes += ret; + ++out.calls; + return ret; +} +catch(const boost::system::system_error &e) +{ + throw_system_error(e); +} + +/// Yields ircd::ctx until one or more bytes are sent. +template +size_t +ircd::net::socket::write_few(iov&& bufs) +try +{ + const auto interruption{[this] + (ctx::ctx *const &) + { + this->cancel(); + }}; + + size_t ret; continuation + { + continuation::asio_predicate, interruption, [this, &ret, &bufs] + (auto &yield) + { + ret = ssl.async_write_some(std::forward(bufs), yield); + } + }; + + out.bytes += ret; + ++out.calls; + return ret; +} +catch(const boost::system::system_error &e) +{ + throw_system_error(e); +} + +/// Non-blocking; writes as much as possible without blocking +template +size_t +ircd::net::socket::write_any(iov&& bufs) +try +{ + static const auto completion + { + asio::transfer_all() + }; + + assert(!blocking(*this)); + const size_t ret + { + asio::write(ssl, std::forward(bufs), completion) + }; + + out.bytes += ret; + ++out.calls; + return ret; +} +catch(const boost::system::system_error &e) +{ + throw_system_error(e); +} + +/// Non-blocking; Writes one "unit" of data or less; never more. +template +size_t +ircd::net::socket::write_one(iov&& bufs) +try +{ + assert(!blocking(*this)); + const size_t ret + { + ssl.write_some(std::forward(bufs)) + }; + + out.bytes += ret; + ++out.calls; + return ret; +} +catch(const boost::system::system_error &e) +{ + throw_system_error(e); +} + void ircd::net::socket::handle_ready(const std::weak_ptr wp, const net::ready type,