mirror of
https://github.com/matrix-construct/construct
synced 2024-12-28 00:14:07 +01:00
ircd::server: Reset necessary link state if any exception before handler.
This commit is contained in:
parent
2e3d88057c
commit
90b7810921
1 changed files with 28 additions and 1 deletions
|
@ -1043,6 +1043,12 @@ ircd::server::link::open(const net::open_opts &open_opts)
|
||||||
init = true;
|
init = true;
|
||||||
fini = false;
|
fini = false;
|
||||||
inc_handles();
|
inc_handles();
|
||||||
|
const unwind::exceptional unhandled{[this]
|
||||||
|
{
|
||||||
|
dec_handles();
|
||||||
|
init = false;
|
||||||
|
}};
|
||||||
|
|
||||||
socket = net::open(open_opts, std::move(handler));
|
socket = net::open(open_opts, std::move(handler));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1055,9 +1061,10 @@ ircd::server::link::handle_open(std::exception_ptr eptr)
|
||||||
dec_handles();
|
dec_handles();
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
assert(init);
|
||||||
init = false;
|
init = false;
|
||||||
|
|
||||||
if(!eptr)
|
if(!eptr && !fini)
|
||||||
wait_writable();
|
wait_writable();
|
||||||
|
|
||||||
if(node)
|
if(node)
|
||||||
|
@ -1087,6 +1094,12 @@ ircd::server::link::close(const net::close_opts &close_opts)
|
||||||
node->disperse(*this);
|
node->disperse(*this);
|
||||||
|
|
||||||
inc_handles();
|
inc_handles();
|
||||||
|
const unwind::exceptional unhandled{[this]
|
||||||
|
{
|
||||||
|
dec_handles();
|
||||||
|
// link may be destroyed here
|
||||||
|
}};
|
||||||
|
|
||||||
net::close(*socket, close_opts, std::move(handler));
|
net::close(*socket, close_opts, std::move(handler));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1099,6 +1112,8 @@ ircd::server::link::handle_close(std::exception_ptr eptr)
|
||||||
dec_handles();
|
dec_handles();
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
assert(fini);
|
||||||
|
|
||||||
if(node)
|
if(node)
|
||||||
node->handle_close(*this, std::move(eptr));
|
node->handle_close(*this, std::move(eptr));
|
||||||
}
|
}
|
||||||
|
@ -1117,6 +1132,12 @@ ircd::server::link::wait_writable()
|
||||||
assert(ready());
|
assert(ready());
|
||||||
inc_handles();
|
inc_handles();
|
||||||
waiting_write = true;
|
waiting_write = true;
|
||||||
|
const unwind::exceptional unhandled{[this]
|
||||||
|
{
|
||||||
|
waiting_write = false;
|
||||||
|
dec_handles();
|
||||||
|
}};
|
||||||
|
|
||||||
net::wait(*socket, net::ready::WRITE, std::move(handler));
|
net::wait(*socket, net::ready::WRITE, std::move(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1266,6 +1287,12 @@ ircd::server::link::wait_readable()
|
||||||
assert(ready());
|
assert(ready());
|
||||||
inc_handles();
|
inc_handles();
|
||||||
waiting_read = true;
|
waiting_read = true;
|
||||||
|
const unwind::exceptional unhandled{[this]
|
||||||
|
{
|
||||||
|
waiting_read = false;
|
||||||
|
dec_handles();
|
||||||
|
}};
|
||||||
|
|
||||||
net::wait(*socket, net::ready::READ, std::move(handler));
|
net::wait(*socket, net::ready::READ, std::move(handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue