refactor: reformat instance.cpp

This commit is contained in:
CJ van den Berg 2024-08-29 14:39:41 +02:00
parent 20339921cf
commit f9704faa94
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -245,8 +245,8 @@ struct instance : std::enable_shared_from_this<instance> {
} }
static auto spawn(context_impl &ctx, behaviour b, exit_handler eh, static auto spawn(context_impl &ctx, behaviour b, exit_handler eh,
string_view name, const ref &link, env_t env) string_view name, const ref &link,
-> expected<handle, error> { env_t env) -> expected<handle, error> {
auto pimpl = make_shared<instance>(ctx, move(b), move(eh), name, move(env)); auto pimpl = make_shared<instance>(ctx, move(b), move(eh), name, move(env));
pimpl->lifetime_ = pimpl; pimpl->lifetime_ = pimpl;
handle_ref(pimpl->self_ref_) = pimpl->lifetime_; handle_ref(pimpl->self_ref_) = pimpl->lifetime_;
@ -447,8 +447,8 @@ struct instance : std::enable_shared_from_this<instance> {
return send_raw(array(std::forward<Ts>(parms)...)); return send_raw(array(std::forward<Ts>(parms)...));
} }
auto spawn_link(behaviour b, string_view name, env_t env) auto spawn_link(behaviour b, string_view name,
-> expected<handle, error> { env_t env) -> expected<handle, error> {
auto ret = instance::spawn(ctx, move(b), exit_handler{}, name, lifetime_, auto ret = instance::spawn(ctx, move(b), exit_handler{}, name, lifetime_,
move(env)); move(env));
if (not ret) if (not ret)
@ -497,10 +497,10 @@ struct instance : std::enable_shared_from_this<instance> {
env_t env_; env_t env_;
}; };
auto deadsend(const buffer &m) -> result { auto deadsend(const buffer &m, const ref &from) -> result {
if (current_instance and !current_instance->is_in_shutdown() and if (current_instance and !current_instance->is_in_shutdown() and
!m("exit", type::more)) { !m("exit", type::more)) {
return to_error(exit_message("DEADSEND", m)); return to_error(exit_message("DEADSEND", m, ref_m(from)));
} }
return ok(); return ok();
} }
@ -550,15 +550,15 @@ auto spawn(behaviour b, string_view name) -> expected<handle, error> {
p.env_); p.env_);
} }
auto spawn(behaviour b, string_view name, env_t env) auto spawn(behaviour b, string_view name,
-> expected<handle, error> { env_t env) -> expected<handle, error> {
auto &p = private_call(); auto &p = private_call();
return instance::spawn(p.ctx, move(b), exit_handler{}, name, thespian::ref{}, return instance::spawn(p.ctx, move(b), exit_handler{}, name, thespian::ref{},
move(env)); move(env));
} }
auto context::spawn(behaviour b, string_view name, env_t env) auto context::spawn(behaviour b, string_view name,
-> expected<handle, error> { env_t env) -> expected<handle, error> {
return instance::spawn(impl(*this), move(b), exit_handler{}, name, return instance::spawn(impl(*this), move(b), exit_handler{}, name,
thespian::ref{}, move(env)); thespian::ref{}, move(env));
} }
@ -576,8 +576,8 @@ auto context::spawn_link(behaviour b, exit_handler eh, string_view name,
move(env)); move(env));
} }
auto context::spawn_link(behaviour b, exit_handler eh, string_view name) auto context::spawn_link(behaviour b, exit_handler eh,
-> expected<handle, error> { string_view name) -> expected<handle, error> {
return spawn_link(move(b), move(eh), name, env_t{}); return spawn_link(move(b), move(eh), name, env_t{});
} }
@ -587,8 +587,8 @@ auto self_ref() -> handle & { return private_call().self_ref_; }
auto spawn_link(behaviour b, string_view name) -> expected<handle, error> { auto spawn_link(behaviour b, string_view name) -> expected<handle, error> {
return private_call().spawn_link(move(b), name); return private_call().spawn_link(move(b), name);
} }
auto spawn_link(behaviour b, string_view name, env_t env) auto spawn_link(behaviour b, string_view name,
-> expected<handle, error> { env_t env) -> expected<handle, error> {
return private_call().spawn_link(move(b), name, move(env)); return private_call().spawn_link(move(b), name, move(env));
} }
auto send_raw(buffer m) -> result { return private_call().send_raw(move(m)); } auto send_raw(buffer m) -> result { return private_call().send_raw(move(m)); }
@ -826,8 +826,8 @@ struct udp_impl {
} }
} }
[[nodiscard]] auto sendto(string_view data, in6_addr ip, port_t port) [[nodiscard]] auto sendto(string_view data, in6_addr ip,
-> size_t { port_t port) -> size_t {
if (is_trace_enabled_) if (is_trace_enabled_)
owner_.env_.trace( owner_.env_.trace(
array("udp", tag_, "sendto", data, executor::to_string(ip), port)); array("udp", tag_, "sendto", data, executor::to_string(ip), port));
@ -867,8 +867,8 @@ auto udp::create(string tag) -> udp {
struct file_descriptor_impl { struct file_descriptor_impl {
file_descriptor_impl(const file_descriptor_impl &) = delete; file_descriptor_impl(const file_descriptor_impl &) = delete;
file_descriptor_impl(file_descriptor_impl &&) = delete; file_descriptor_impl(file_descriptor_impl &&) = delete;
auto operator=(const file_descriptor_impl &) auto
-> file_descriptor_impl & = delete; operator=(const file_descriptor_impl &) -> file_descriptor_impl & = delete;
auto operator=(file_descriptor_impl &&) -> file_descriptor_impl & = delete; auto operator=(file_descriptor_impl &&) -> file_descriptor_impl & = delete;
file_descriptor_impl(string_view tag, int fd) file_descriptor_impl(string_view tag, int fd)
@ -961,8 +961,8 @@ struct file_stream_impl {
liffile_stream_elock{owner_.lifetime_}]( liffile_stream_elock{owner_.lifetime_}](
error_code ec, size_t bytes_written) { error_code ec, size_t bytes_written) {
if (ec) { if (ec) {
auto _ = auto _ = owner_.send("stream", tag_, "write_error", ec.value(),
owner_.send("stream", tag_, "write_error", ec.value(), ec.message()); ec.message());
} else { } else {
auto _ = owner_.send("stream", tag_, "write_complete", bytes_written); auto _ = owner_.send("stream", tag_, "write_complete", bytes_written);
} }
@ -1497,8 +1497,8 @@ struct connection {
return ok(); return ok();
} }
static auto start(int fd, const handle &owner, const char *tag) static auto start(int fd, const handle &owner,
-> expected<handle, error> { const char *tag) -> expected<handle, error> {
return spawn( return spawn(
[fd, owner, tag]() { [fd, owner, tag]() {
link(owner); link(owner);
@ -1736,8 +1736,8 @@ struct acceptor {
string listen_path; string listen_path;
acceptor(string_view path, mode m, handle o) acceptor(string_view path, mode m, handle o)
: a{::thespian::unx::acceptor::create(tag)}, owner{move(o)}, listen_path{ : a{::thespian::unx::acceptor::create(tag)}, owner{move(o)},
path} { listen_path{path} {
a.listen(path, m); a.listen(path, m);
} }
~acceptor() = default; ~acceptor() = default;
@ -1993,8 +1993,8 @@ struct connection {
return ok(); return ok();
} }
static auto start(context_impl &ctx, int fd, const string &prompt) static auto start(context_impl &ctx, int fd,
-> expected<handle, error> { const string &prompt) -> expected<handle, error> {
return spawn( return spawn(
[&ctx, fd, prompt]() { [&ctx, fd, prompt]() {
::thespian::receive( ::thespian::receive(
@ -2050,8 +2050,8 @@ struct acceptor {
return ok(); return ok();
} }
static auto start(context_impl &ctx, port_t port, const string &prompt) static auto start(context_impl &ctx, port_t port,
-> expected<handle, error> { const string &prompt) -> expected<handle, error> {
return spawn( return spawn(
[&ctx, port, prompt]() { [&ctx, port, prompt]() {
::thespian::receive( ::thespian::receive(
@ -2064,8 +2064,8 @@ struct acceptor {
} }
}; };
auto create(context &ctx, port_t port, const string &prompt) auto create(context &ctx, port_t port,
-> expected<handle, error> { const string &prompt) -> expected<handle, error> {
return acceptor::start(impl(ctx), port, prompt); return acceptor::start(impl(ctx), port, prompt);
} }