///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| 102 | |
| 103 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 104 | void FSecure::C3::Core::DeviceBridge::StartUpdatingInSeparateThread() |
| 105 | { |
| 106 | std::thread{ |
| 107 | [this, self = shared_from_this()]() |
| 108 | { |
| 109 | WinTools::StructuredExceptionHandling::SehWrapper([&]() |
| 110 | { |
| 111 | while (m_IsAlive) |
| 112 | try |
| 113 | { |
| 114 | std::this_thread::sleep_for(GetDevice()->GetUpdateDelay()); |
| 115 | |
| 116 | OnReceive(); |
| 117 | |
| 118 | // Give the other end some time to respond to the receive if a fast comms mechanism. |
| 119 | std::this_thread::sleep_for(std::chrono::milliseconds(50)); |
| 120 | |
| 121 | // Previous bug occurred where we only received when sendqueue was empty |
| 122 | // But if sendqueue fills faster than the update delay then we never receive a message |
| 123 | if (!m_SendQueue.empty()) |
| 124 | { |
| 125 | ByteVector msg; |
| 126 | { |
| 127 | auto lock = std::lock_guard<std::mutex>{ m_ProtectWriteInConcurrentThreads }; |
| 128 | msg = std::move(m_SendQueue.front()); |
| 129 | m_SendQueue.pop_front(); |
| 130 | } |
| 131 | OnSend(msg); |
| 132 | } |
| 133 | } |
| 134 | catch (std::exception const& exception) |
| 135 | { |
| 136 | Log({ OBF_SEC("std::exception while updating: ") + exception.what(), LogMessage::Severity::Error }); |
| 137 | } |
| 138 | catch (...) |
| 139 | { |
| 140 | Log({ OBF_SEC("Unknown exception while updating."), LogMessage::Severity::Error }); |
| 141 | } |
| 142 | }, [this]() |
| 143 | { |
| 144 | # if defined _DEBUG |
| 145 | Log({ "Signal captured, ending thread execution.", LogMessage::Severity::Error }); |
| 146 | # endif |
| 147 | }); |
| 148 | }}.detach(); |
| 149 | } |
| 150 | |
| 151 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 152 | void FSecure::C3::Core::DeviceBridge::SetUpdateDelay(std::chrono::milliseconds minUpdateDelayInMs, std::chrono::milliseconds maxUpdateDelayInMs) |
no test coverage detected