///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| 63 | |
| 64 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 | void FSecure::DuplexConnection::StartReceiving(std::function<void(ByteVector)> callback) |
| 66 | { |
| 67 | m_IsReceiving = true; |
| 68 | m_ReceivingThread = std::thread([this, callback]() |
| 69 | { |
| 70 | try |
| 71 | { |
| 72 | while (true) |
| 73 | { |
| 74 | if (m_IsReceiving && !m_ClientSocket.HasReceivedData()) |
| 75 | { |
| 76 | std::this_thread::sleep_for(10ms); |
| 77 | continue; |
| 78 | } |
| 79 | if (!m_IsReceiving) |
| 80 | break; |
| 81 | |
| 82 | auto message = Receive(); |
| 83 | if (!m_IsReceiving || message.empty()) |
| 84 | break; |
| 85 | callback(std::move(message)); |
| 86 | } |
| 87 | } |
| 88 | catch (FSecure::SocketsException&) |
| 89 | { |
| 90 | Stop(); |
| 91 | } |
| 92 | }); |
| 93 | } |
| 94 | |
| 95 | void FSecure::DuplexConnection::Stop() |
| 96 | { |
no test coverage detected