Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
danieltabacaru committed Sep 27, 2024
1 parent 8ecb791 commit d4ca54f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
27 changes: 18 additions & 9 deletions src/realm/sync/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,15 +827,7 @@ bool SessionImpl::process_flx_bootstrap_message(const DownloadMessage& message)
return true;
}

try {
process_pending_flx_bootstrap(); // throws
}
catch (const IntegrationException& e) {
on_integration_failure(e);
}
catch (...) {
on_integration_failure(IntegrationException(exception_to_status()));
}
try_process_pending_flx_bootstrap();

return true;
}
Expand All @@ -847,6 +839,10 @@ void SessionImpl::process_pending_flx_bootstrap()
if (!m_is_flx_sync_session || m_state != State::Active) {
return;
}
// Ignore the call if the client detects an error.
if (m_client_error) {
return;
}
auto bootstrap_store = m_wrapper.get_flx_pending_bootstrap_store();
if (!bootstrap_store->has_pending()) {
return;
Expand Down Expand Up @@ -917,6 +913,19 @@ void SessionImpl::process_pending_flx_bootstrap()
REALM_ASSERT_EX(action == SyncClientHookAction::NoAction || action == SyncClientHookAction::EarlyReturn, action);
}

void SessionImpl::try_process_pending_flx_bootstrap()
{
try {
process_pending_flx_bootstrap(); // throws
}
catch (const IntegrationException& error) {
on_integration_failure(error);
}
catch (...) {
on_integration_failure(IntegrationException(exception_to_status()));
}
}

void SessionImpl::on_flx_sync_error(int64_t version, std::string_view err_msg)
{
// Ignore the call if the session is not active
Expand Down
12 changes: 3 additions & 9 deletions src/realm/sync/noinst/client_impl_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,15 +1513,7 @@ void Session::cancel_resumption_delay()
if (unbind_process_complete())
initiate_rebind(); // Throws

try {
process_pending_flx_bootstrap(); // throws
}
catch (const IntegrationException& error) {
on_integration_failure(error);
}
catch (...) {
on_integration_failure(IntegrationException(exception_to_status()));
}
try_process_pending_flx_bootstrap();

m_conn.one_more_active_unsuspended_session(); // Throws
if (m_try_again_activation_timer) {
Expand Down Expand Up @@ -1709,6 +1701,8 @@ void Session::activate()
REALM_ASSERT(!m_suspended);
m_conn.one_more_active_unsuspended_session(); // Throws

try_process_pending_flx_bootstrap();

// Checks if there is a pending client reset
handle_pending_client_reset_acknowledgement();
}
Expand Down
12 changes: 2 additions & 10 deletions src/realm/sync/noinst/client_impl_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ class ClientImpl::Session {

// Processes any pending FLX bootstraps, if one exists. Otherwise this is a noop.
void process_pending_flx_bootstrap();
void try_process_pending_flx_bootstrap();

bool client_reset_if_needed();
void handle_pending_client_reset_acknowledgement();
Expand All @@ -941,7 +942,6 @@ class ClientImpl::Session {
void begin_resumption_delay(const ProtocolErrorInfo& error_info);
void clear_resumption_delay_state();

private:
Connection& m_conn;
const session_ident_type m_ident;

Expand Down Expand Up @@ -1398,15 +1398,7 @@ inline void ClientImpl::Session::connection_established(bool fast_reconnect)
// the bind messsage
call_debug_hook(SyncClientHookEvent::SessionConnected);

try {
process_pending_flx_bootstrap(); // throws
}
catch (const IntegrationException& error) {
on_integration_failure(error);
}
catch (...) {
on_integration_failure(IntegrationException(exception_to_status()));
}
try_process_pending_flx_bootstrap();

if (!m_suspended) {
// Ready to send BIND message
Expand Down

0 comments on commit d4ca54f

Please sign in to comment.