mirror of
https://github.com/matrix-construct/construct
synced 2024-11-12 04:51:08 +01:00
ircd::net: Fix the asio callback and error_code interp on socket waits.
This commit is contained in:
parent
fcf19bc002
commit
a280350dee
2 changed files with 22 additions and 14 deletions
|
@ -70,7 +70,7 @@ struct ircd::net::socket
|
||||||
void handle_handshake(std::weak_ptr<socket>, eptr_handler, error_code) noexcept;
|
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_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_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:
|
public:
|
||||||
operator const ip::tcp::socket &() const { return sd; }
|
operator const ip::tcp::socket &() const { return sd; }
|
||||||
|
|
34
ircd/net.cc
34
ircd/net.cc
|
@ -3089,7 +3089,7 @@ try
|
||||||
|
|
||||||
auto handle
|
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)
|
switch(opts.type)
|
||||||
|
@ -3108,31 +3108,43 @@ try
|
||||||
{
|
{
|
||||||
ircd::post(desc[1], [handle(std::move(handle))]
|
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
|
// 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
|
// 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
|
// using a non-blocking peek in the handler. By doing it this way here we
|
||||||
// just get the error in the handler's ec.
|
// 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(bufs, sd.message_peek, ios::handle(desc[1], [handle(std::move(handle))]
|
||||||
//sd.async_wait(wait_type::wait_read, std::move(handle));
|
sd.async_receive(bufs, sd.message_peek, ios::handle(desc[1], [handle(std::move(handle))]
|
||||||
break;
|
(const auto &ec, const size_t bytes)
|
||||||
|
{
|
||||||
|
handle
|
||||||
|
(
|
||||||
|
!ec && bytes?
|
||||||
|
error_code{}:
|
||||||
|
!ec && !bytes?
|
||||||
|
net::eof:
|
||||||
|
make_error_code(ec)
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ready::WRITE:
|
case ready::WRITE:
|
||||||
{
|
{
|
||||||
sd.async_wait(wait_type::wait_write, ios::handle(desc[2], std::move(handle)));
|
sd.async_wait(wait_type::wait_write, ios::handle(desc[2], std::move(handle)));
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ready::ERROR:
|
case ready::ERROR:
|
||||||
{
|
{
|
||||||
sd.async_wait(wait_type::wait_error, ios::handle(desc[3], std::move(handle)));
|
sd.async_wait(wait_type::wait_error, ios::handle(desc[3], std::move(handle)));
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
default: throw ircd::not_implemented{};
|
default: throw ircd::not_implemented{};
|
||||||
|
@ -3445,8 +3457,7 @@ void
|
||||||
ircd::net::socket::handle_ready(const std::weak_ptr<socket> wp,
|
ircd::net::socket::handle_ready(const std::weak_ptr<socket> wp,
|
||||||
const net::ready type,
|
const net::ready type,
|
||||||
const ec_handler callback,
|
const ec_handler callback,
|
||||||
error_code ec,
|
error_code ec)
|
||||||
const size_t bytes)
|
|
||||||
noexcept try
|
noexcept try
|
||||||
{
|
{
|
||||||
using std::errc;
|
using std::errc;
|
||||||
|
@ -3463,9 +3474,6 @@ noexcept try
|
||||||
if(unlikely(!ec && !sd.is_open()))
|
if(unlikely(!ec && !sd.is_open()))
|
||||||
ec = make_error_code(errc::bad_file_descriptor);
|
ec = make_error_code(errc::bad_file_descriptor);
|
||||||
|
|
||||||
if(type == ready::READ && !ec && bytes == 0)
|
|
||||||
ec = eof;
|
|
||||||
|
|
||||||
#ifdef IRCD_DEBUG_NET_SOCKET_READY
|
#ifdef IRCD_DEBUG_NET_SOCKET_READY
|
||||||
const auto has_pending
|
const auto has_pending
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue