generic_server: add on_connection_ready handler

This patch cleans the code a bit so that ready state is set in a single place.
And adds handler which will allow adding logic when connection is made
ready, this will be added in the following commits.
This commit is contained in:
Marcin Maliszkiewicz
2025-02-20 14:49:54 +01:00
parent 69684e16d8
commit 474e84199c
4 changed files with 10 additions and 0 deletions

View File

@@ -129,6 +129,10 @@ future<> connection::process()
});
}
void connection::on_connection_ready()
{
}
void connection::on_connection_close()
{
}

View File

@@ -62,6 +62,8 @@ public:
virtual future<> process_request() = 0;
virtual void on_connection_ready();
virtual void on_connection_close();
virtual future<> shutdown();

View File

@@ -108,6 +108,7 @@ future<> redis_server::connection::process_request() {
_pending_requests_gate.enter();
utils::latency_counter lc;
lc.start();
on_connection_ready();
auto leave = defer([this] () noexcept { _pending_requests_gate.leave(); });
return process_request_internal().then([this, leave = std::move(leave), lc = std::move(lc)] (auto&& result) mutable {
--_server._stats._requests_serving;

View File

@@ -934,6 +934,7 @@ future<std::unique_ptr<cql_server::response>> cql_server::connection::process_st
}
} else {
_ready = true;
on_connection_ready();
res = make_ready(stream, trace_state);
}
@@ -967,6 +968,7 @@ future<std::unique_ptr<cql_server::response>> cql_server::connection::process_au
return f.then([this, stream, challenge = std::move(challenge), trace_state]() mutable {
_authenticating = false;
_ready = true;
on_connection_ready();
return make_ready_future<std::unique_ptr<cql_server::response>>(make_auth_success(stream, std::move(challenge), trace_state));
});
});
@@ -1324,6 +1326,7 @@ cql_server::connection::process_register(uint16_t stream, request_reader in, ser
_server._notifier->register_event(et, this);
}
_ready = true;
on_connection_ready();
return make_ready_future<std::unique_ptr<cql_server::response>>(make_ready(stream, std::move(trace_state)));
}