• 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

94.12
/src/realm/sync/network/default_socket.hpp
1
#pragma once
2

3
#include <realm/sync/binding_callback_thread_observer.hpp>
4
#include <realm/sync/config.hpp>
5
#include <realm/sync/socket_provider.hpp>
6
#include <realm/sync/network/http.hpp>
7
#include <realm/sync/network/network.hpp>
8
#include <realm/util/future.hpp>
9
#include <realm/util/tagged_bool.hpp>
10

11
#include <map>
12
#include <random>
13
#include <system_error>
14
#include <thread>
15

16
namespace realm::sync::network {
17
class Service;
18
} // namespace realm::sync::network
19

20
namespace realm::sync::websocket {
21
using port_type = sync::port_type;
22

23
class DefaultSocketProvider : public SyncSocketProvider {
24
public:
25
    class Timer : public SyncSocketProvider::Timer {
26
    public:
27
        friend class DefaultSocketProvider;
28

29
        /// Cancels the timer and destroys the timer instance.
30
        ~Timer() = default;
16,708✔
31

32
        /// Cancel the timer immediately
33
        void cancel() override
34
        {
16✔
35
            m_timer.cancel();
16✔
36
        }
16✔
37

38
    protected:
39
        Timer(network::Service& service, std::chrono::milliseconds delay, FunctionHandler&& handler)
40
            : m_timer{service}
41
        {
16,706✔
42
            m_timer.async_wait(delay, std::move(handler));
16,706✔
43
        }
16,706✔
44

45
    private:
46
        network::DeadlineTimer m_timer;
47
    };
48

49
    struct AutoStartTag {
50
    };
51

52
    using AutoStart = util::TaggedBool<AutoStartTag>;
53
    DefaultSocketProvider(const std::shared_ptr<util::Logger>& logger, const std::string& user_agent,
54
                          const std::shared_ptr<BindingCallbackThreadObserver>& observer_ptr = nullptr,
55
                          AutoStart auto_start = AutoStart{true});
56

57
    ~DefaultSocketProvider();
58

59
    // Start the event loop if it is not started already. Otherwise, do nothing.
60
    void start();
61

62
    /// Temporary workaround until client shutdown has been updated in a separate PR - these functions
63
    /// will be handled internally when this happens.
64
    /// Stops the internal event loop (provided by network::Service)
65
    void stop(bool wait_for_stop = false) override;
66

67
    std::unique_ptr<WebSocketInterface> connect(std::unique_ptr<WebSocketObserver>, WebSocketEndpoint&&) override;
68

69
    void post(FunctionHandler&& handler) override
70
    {
178,622✔
71
        // Don't post empty handlers onto the event loop
89,900✔
72
        if (!handler)
178,622✔
UNCOV
73
            return;
×
74
        m_service.post(std::move(handler));
178,622✔
75
    }
178,622✔
76

77
    SyncTimer create_timer(std::chrono::milliseconds delay, FunctionHandler&& handler) override
78
    {
16,704✔
79
        return std::unique_ptr<Timer>(new DefaultSocketProvider::Timer(m_service, delay, std::move(handler)));
16,704✔
80
    }
16,704✔
81

82
    struct OnlyForTesting {
83
        // Runs the event loop as though start() was called on the current thread so that the caller
84
        // can catch and handle any thrown exceptions in tests.
85
        static void run_event_loop_on_current_thread(DefaultSocketProvider* provider);
86

87
        static void prep_event_loop_for_restart(DefaultSocketProvider* provider);
88
    };
89

90
private:
91
    enum class State { Starting, Running, Stopping, Stopped };
92

93
    /// Block until the state reaches the expected or later state - return true if state matches expected state
94
    void state_wait_for(std::unique_lock<std::mutex>& lock, State expected_state);
95
    /// Internal function for updating the state and signaling the wait_for_state condvar
96
    void do_state_update(std::unique_lock<std::mutex>&, State new_state);
97
    /// The execution code for the event loop thread
98
    void event_loop();
99

100
    std::shared_ptr<util::Logger> m_logger_ptr;
101
    std::shared_ptr<BindingCallbackThreadObserver> m_observer_ptr;
102
    network::Service m_service;
103
    std::mt19937_64 m_random;
104
    const std::string m_user_agent;
105
    std::mutex m_mutex;
106
    uint64_t m_event_loop_generation = 0;
107
    State m_state;                      // protected by m_mutex
108
    std::condition_variable m_state_cv; // uses m_mutex
109
    std::thread m_thread;               // protected by m_mutex
110
};
111

112
/// Class for the Default Socket Provider websockets that allows a simulated
113
/// http response to be specified for testing.
114
class DefaultWebSocket : public WebSocketInterface {
115
public:
116
    virtual ~DefaultWebSocket() = default;
3,456✔
117

118
    virtual void force_handshake_response_for_testing(int status_code, std::string body = "") = 0;
119

120
protected:
121
};
122

123
} // namespace realm::sync::websocket
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