0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-16 00:48:26 +02:00

ircd::net: Fix the asio callback and error_code interp on socket waits.

This commit is contained in:
Jason Volk 2019-09-13 12:30:05 -07:00
parent fcf19bc002
commit a280350dee
2 changed files with 22 additions and 14 deletions

View file

@ -70,7 +70,7 @@ struct ircd::net::socket
void handle_handshake(std::weak_ptr<socket>, eptr_handler, error_code) noexcept;
void handle_connect(std::weak_ptr<socket>, const open_opts &, eptr_handler, error_code) noexcept;
void handle_timeout(std::weak_ptr<socket>, ec_handler, error_code) noexcept;
void handle_ready(std::weak_ptr<socket>, ready, ec_handler, error_code, size_t) noexcept;
void handle_ready(std::weak_ptr<socket>, ready, ec_handler, error_code) noexcept;
public:
operator const ip::tcp::socket &() const { return sd; }

View file

@ -3089,7 +3089,7 @@ try
auto handle
{
std::bind(&socket::handle_ready, this, weak_from(*this), opts.type, std::move(callback), ph::_1, 0UL)
std::bind(&socket::handle_ready, this, weak_from(*this), opts.type, std::move(callback), ph::_1)
};
switch(opts.type)
@ -3108,31 +3108,43 @@ try
{
ircd::post(desc[1], [handle(std::move(handle))]
{
handle(error_code{}, 1UL);
handle(error_code{});
});
break;
return;
}
// The problem here is that the wait operation gives ec=success on both a
// socket error and when data is actually available. We then have to check
// using a non-blocking peek in the handler. By doing it this way here we
// just get the error in the handler's ec.
sd.async_receive(bufs, sd.message_peek, ios::handle(desc[1], std::move(handle)));
//sd.async_wait(wait_type::wait_read, std::move(handle));
break;
//sd.async_wait(bufs, sd.message_peek, ios::handle(desc[1], [handle(std::move(handle))]
sd.async_receive(bufs, sd.message_peek, ios::handle(desc[1], [handle(std::move(handle))]
(const auto &ec, const size_t bytes)
{
handle
(
!ec && bytes?
error_code{}:
!ec && !bytes?
net::eof:
make_error_code(ec)
);
}));
return;
}
case ready::WRITE:
{
sd.async_wait(wait_type::wait_write, ios::handle(desc[2], std::move(handle)));
break;
return;
}
case ready::ERROR:
{
sd.async_wait(wait_type::wait_error, ios::handle(desc[3], std::move(handle)));
break;
return;
}
default: throw ircd::not_implemented{};
@ -3445,8 +3457,7 @@ void
ircd::net::socket::handle_ready(const std::weak_ptr<socket> wp,
const net::ready type,
const ec_handler callback,
error_code ec,
const size_t bytes)
error_code ec)
noexcept try
{
using std::errc;
@ -3463,9 +3474,6 @@ noexcept try
if(unlikely(!ec && !sd.is_open()))
ec = make_error_code(errc::bad_file_descriptor);
if(type == ready::READ && !ec && bytes == 0)
ec = eof;
#ifdef IRCD_DEBUG_NET_SOCKET_READY
const auto has_pending
{