0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 22:41:12 +01:00

ircd::net: Propagate ctx interruption to socket.

This commit is contained in:
Jason Volk 2018-04-15 16:12:50 -07:00
parent f4b2273a4b
commit 49d83de384
2 changed files with 49 additions and 7 deletions

View file

@ -131,9 +131,18 @@ ircd::net::socket::read_all(iov&& bufs)
asio::transfer_all() asio::transfer_all()
}; };
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
const size_t ret const size_t ret
{ {
asio::async_read(ssl, std::forward<iov>(bufs), completion, yield_context{to_asio{}}) asio::async_read(ssl, std::forward<iov>(bufs), completion, yield_context
{
to_asio{interruption}
})
}; };
if(!ret) if(!ret)
@ -152,9 +161,18 @@ template<class iov>
size_t size_t
ircd::net::socket::read_few(iov&& bufs) ircd::net::socket::read_few(iov&& bufs)
{ {
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
const size_t ret const size_t ret
{ {
ssl.async_read_some(std::forward<iov>(bufs), yield_context{to_asio{}}) ssl.async_read_some(std::forward<iov>(bufs), yield_context
{
to_asio{interruption}
})
}; };
if(!ret) if(!ret)
@ -215,9 +233,18 @@ ircd::net::socket::write_all(iov&& bufs)
asio::transfer_all() asio::transfer_all()
}; };
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
const size_t ret const size_t ret
{ {
asio::async_write(ssl, std::forward<iov>(bufs), completion, yield_context{to_asio{}}) asio::async_write(ssl, std::forward<iov>(bufs), completion, yield_context
{
to_asio{interruption}
})
}; };
out.bytes += ret; out.bytes += ret;
@ -230,9 +257,18 @@ template<class iov>
size_t size_t
ircd::net::socket::write_few(iov&& bufs) ircd::net::socket::write_few(iov&& bufs)
{ {
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
const size_t ret const size_t ret
{ {
ssl.async_write_some(std::forward<iov>(bufs), yield_context{to_asio{}}) ssl.async_write_some(std::forward<iov>(bufs), yield_context
{
to_asio{interruption}
})
}; };
out.bytes += ret; out.bytes += ret;

View file

@ -1611,6 +1611,12 @@ void
ircd::net::socket::wait(const wait_opts &opts) ircd::net::socket::wait(const wait_opts &opts)
try try
{ {
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
const scope_timeout timeout const scope_timeout timeout
{ {
*this, opts.timeout *this, opts.timeout
@ -1619,15 +1625,15 @@ try
switch(opts.type) switch(opts.type)
{ {
case ready::ERROR: case ready::ERROR:
sd.async_wait(wait_type::wait_error, yield_context{to_asio{}}); sd.async_wait(wait_type::wait_error, yield_context{to_asio{interruption}});
break; break;
case ready::WRITE: case ready::WRITE:
sd.async_wait(wait_type::wait_write, yield_context{to_asio{}}); sd.async_wait(wait_type::wait_write, yield_context{to_asio{interruption}});
break; break;
case ready::READ: case ready::READ:
sd.async_wait(wait_type::wait_read, yield_context{to_asio{}}); sd.async_wait(wait_type::wait_read, yield_context{to_asio{interruption}});
break; break;
default: default: