From 27287aea50b9416b33be713765157ff1ea752821 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Thu, 9 Jan 2020 13:30:08 -0800 Subject: [PATCH] ws send / detect disconnection earlier --- ws/ws_broadcast_server.cpp | 2 +- ws/ws_send.cpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ws/ws_broadcast_server.cpp b/ws/ws_broadcast_server.cpp index abeca557..84fbf265 100644 --- a/ws/ws_broadcast_server.cpp +++ b/ws/ws_broadcast_server.cpp @@ -72,7 +72,7 @@ namespace ix size_t bufferedAmount = client->bufferedAmount(); spdlog::info("{} bytes left to be sent", bufferedAmount); - std::chrono::duration duration(10); + std::chrono::duration duration(500); std::this_thread::sleep_for(duration); } while (client->bufferedAmount() != 0); } diff --git a/ws/ws_send.cpp b/ws/ws_send.cpp index 733eef5e..208fdd10 100644 --- a/ws/ws_send.cpp +++ b/ws/ws_send.cpp @@ -258,7 +258,7 @@ namespace ix MsgPack msg(pdu); Bench bench("Sending file through websocket"); - auto result = _webSocket.sendBinary(msg.dump(), [throttle](int current, int total) -> bool { + auto result = _webSocket.sendBinary(msg.dump(), [this, throttle](int current, int total) -> bool { spdlog::info("ws_send: Step {} out of {}", current + 1, total); if (throttle) @@ -267,7 +267,7 @@ namespace ix std::this_thread::sleep_for(duration); } - return true; + return _connected; }); if (!result.success) @@ -276,12 +276,18 @@ namespace ix return false; } + if (!_connected) + { + spdlog::error("ws_send: Got disconnected from the server"); + return false; + } + do { size_t bufferedAmount = _webSocket.bufferedAmount(); spdlog::info("ws_send: {} bytes left to be sent", bufferedAmount); - std::chrono::duration duration(10); + std::chrono::duration duration(500); std::this_thread::sleep_for(duration); } while (_webSocket.bufferedAmount() != 0 && _connected);