0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +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()
};
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
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)
@ -152,9 +161,18 @@ template<class iov>
size_t
ircd::net::socket::read_few(iov&& bufs)
{
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
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)
@ -215,9 +233,18 @@ ircd::net::socket::write_all(iov&& bufs)
asio::transfer_all()
};
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
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;
@ -230,9 +257,18 @@ template<class iov>
size_t
ircd::net::socket::write_few(iov&& bufs)
{
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
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;

View file

@ -1611,6 +1611,12 @@ void
ircd::net::socket::wait(const wait_opts &opts)
try
{
const auto interruption{[this]
(ctx::ctx *const &) noexcept
{
this->cancel();
}};
const scope_timeout timeout
{
*this, opts.timeout
@ -1619,15 +1625,15 @@ try
switch(opts.type)
{
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;
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;
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;
default: