• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / 2213

10 Apr 2024 11:21PM UTC coverage: 91.792% (-0.8%) from 92.623%
2213

push

Evergreen

web-flow
Add missing availability checks for SecCopyErrorMessageString (#7577)

This requires iOS 11.3 and we currently target iOS 11.

94842 of 175770 branches covered (53.96%)

7 of 22 new or added lines in 2 files covered. (31.82%)

1861 existing lines in 82 files now uncovered.

242866 of 264583 relevant lines covered (91.79%)

5593111.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.65
/src/realm/object-store/sync/impl/sync_client.hpp
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2016 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
#ifndef REALM_OS_SYNC_CLIENT_HPP
20
#define REALM_OS_SYNC_CLIENT_HPP
21

22
#include <realm/sync/client.hpp>
23
#include <realm/sync/network/default_socket.hpp>
24
#include <realm/util/platform_info.hpp>
25
#include <realm/util/scope_exit.hpp>
26

27
#include <thread>
28

29
#include <realm/object-store/sync/sync_manager.hpp>
30
#include <realm/object-store/sync/impl/network_reachability.hpp>
31

32
#if NETWORK_REACHABILITY_AVAILABLE
33
#include <realm/object-store/sync/impl/apple/network_reachability_observer.hpp>
34
#endif
35

36
#ifdef __EMSCRIPTEN__
37
#include <realm/object-store/sync/impl/emscripten/socket_provider.hpp>
38
#endif
39

40
namespace realm::_impl {
41

42
struct SyncClient {
43
    SyncClient(const std::shared_ptr<util::Logger>& logger, SyncClientConfig const& config,
44
               std::weak_ptr<const SyncManager> weak_sync_manager)
45
        : m_socket_provider([&]() -> std::shared_ptr<sync::SyncSocketProvider> {
4,427✔
46
            if (config.socket_provider) {
4,427✔
47
                return config.socket_provider;
28✔
48
            }
28✔
49
#ifdef __EMSCRIPTEN__
50
            return std::make_shared<EmscriptenSocketProvider>();
51
#else
52
            auto user_agent = util::format("RealmSync/%1 (%2) %3 %4", REALM_VERSION_STRING, util::get_platform_info(),
4,399✔
53
                                           config.user_agent_binding_info, config.user_agent_application_info);
4,399✔
54
            return std::make_shared<sync::websocket::DefaultSocketProvider>(
4,399✔
55
                logger, std::move(user_agent), config.default_socket_provider_thread_observer);
4,399✔
56
#endif
4,399✔
57
        }())
4,399✔
58
        , m_client([&] {
4,427✔
59
            sync::Client::Config c;
4,427✔
60
            c.logger = logger;
4,427✔
61
            c.socket_provider = m_socket_provider;
4,427✔
62
            c.reconnect_mode = config.reconnect_mode;
4,427✔
63
            c.one_connection_per_session = !config.multiplex_sessions;
4,427✔
64

2,178✔
65
            // Only set the timeouts if they have sensible values
2,178✔
66
            if (config.timeouts.connect_timeout >= 1000)
4,427✔
67
                c.connect_timeout = config.timeouts.connect_timeout;
4,427✔
68
            if (config.timeouts.connection_linger_time > 0)
4,427✔
69
                c.connection_linger_time = config.timeouts.connection_linger_time;
3,912✔
70
            if (config.timeouts.ping_keepalive_period > 5000)
4,427✔
71
                c.ping_keepalive_period = config.timeouts.ping_keepalive_period;
4,427✔
72
            if (config.timeouts.pong_keepalive_timeout > 5000)
4,427✔
73
                c.pong_keepalive_timeout = config.timeouts.pong_keepalive_timeout;
4,427✔
74
            if (config.timeouts.fast_reconnect_limit > 1000)
4,427✔
75
                c.fast_reconnect_limit = config.timeouts.fast_reconnect_limit;
4,427✔
76
            c.reconnect_backoff_info.resumption_delay_interval =
4,427✔
77
                config.timeouts.reconnect_backoff_info.resumption_delay_interval;
4,427✔
78
            c.reconnect_backoff_info.max_resumption_delay_interval =
4,427✔
79
                config.timeouts.reconnect_backoff_info.max_resumption_delay_interval;
4,427✔
80
            c.reconnect_backoff_info.resumption_delay_backoff_multiplier =
4,427✔
81
                config.timeouts.reconnect_backoff_info.resumption_delay_backoff_multiplier;
4,427✔
82
            if (c.reconnect_backoff_info.resumption_delay_interval.count() < 1000)
4,427✔
UNCOV
83
                logger->warn("A resumption delay interval less than 1000 (1 second) is not recommended");
×
84
            if (c.reconnect_backoff_info.resumption_delay_backoff_multiplier < 1)
4,427✔
UNCOV
85
                throw InvalidArgument("Delay backoff multiplier in reconnect backoff info cannot be less than 1");
×
86
            return c;
4,427✔
87
        }())
4,427✔
88
        , m_logger_ptr(logger)
89
        , m_logger(*m_logger_ptr)
90
#if NETWORK_REACHABILITY_AVAILABLE
91
        , m_reachability_observer(none, [weak_sync_manager](const NetworkReachabilityStatus status) {
92
            if (status != NotReachable) {
×
93
                if (auto sync_manager = weak_sync_manager.lock()) {
×
94
                    sync_manager->reconnect();
95
                }
96
            }
97
        })
98
    {
2,249✔
99
        if (!m_reachability_observer.start_observing())
2,249✔
100
            m_logger.error("Failed to set up network reachability observer");
101
    }
2,249✔
102
#else
103
    {
2,178✔
104
        static_cast<void>(weak_sync_manager);
2,178✔
105
    }
2,178✔
106
#endif
107

108
    void cancel_reconnect_delay()
UNCOV
109
    {
×
110
        m_client.cancel_reconnect_delay();
×
111
    }
×
112

113
    void stop()
114
    {
4,427✔
115
        m_client.shutdown();
4,427✔
116
    }
4,427✔
117

118
    void voluntary_disconnect_all_connections()
119
    {
6✔
120
        m_client.voluntary_disconnect_all_connections();
6✔
121
    }
6✔
122

123
    std::unique_ptr<sync::Session> make_session(std::shared_ptr<DB> db,
124
                                                std::shared_ptr<sync::SubscriptionStore> flx_sub_store,
125
                                                std::shared_ptr<sync::MigrationStore> migration_store,
126
                                                sync::Session::Config config)
127
    {
1,985✔
128
        return std::make_unique<sync::Session>(m_client, std::move(db), std::move(flx_sub_store),
1,985✔
129
                                               std::move(migration_store), std::move(config));
1,985✔
130
    }
1,985✔
131

132
    bool decompose_server_url(const std::string& url, sync::ProtocolEnvelope& protocol, std::string& address,
133
                              sync::Client::port_type& port, std::string& path) const
134
    {
1,985✔
135
        return m_client.decompose_server_url(url, protocol, address, port, path);
1,985✔
136
    }
1,985✔
137

138
    void wait_for_session_terminations()
139
    {
4,608✔
140
        m_client.wait_for_session_terminations_or_client_stopped();
4,608✔
141
    }
4,608✔
142

143
    // Async version of wait_for_session_terminations().
144
    util::Future<void> notify_session_terminated()
145
    {
28✔
146
        return m_client.notify_session_terminated();
28✔
147
    }
28✔
148

149
private:
150
    std::shared_ptr<sync::SyncSocketProvider> m_socket_provider;
151
    sync::Client m_client;
152
    std::shared_ptr<util::Logger> m_logger_ptr;
153
    util::Logger& m_logger;
154
#if NETWORK_REACHABILITY_AVAILABLE
155
    NetworkReachabilityObserver m_reachability_observer;
156
#endif
157
};
158

159
} // namespace realm::_impl
160

161
#endif // REALM_OS_SYNC_CLIENT_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc