(websocket client) better error propagation when errors are detected while sending data + (ws send) detect failures to send big files, terminate in those cases and report error (troubleshooting #140)

This commit is contained in:
Benjamin Sergeant
2020-01-06 14:34:09 -08:00
parent c10ff1d210
commit 7c63232157
6 changed files with 844 additions and 20 deletions

View File

@ -37,7 +37,7 @@ namespace ix
void waitForConnection();
void waitForAck();
void sendMessage(const std::string& filename, bool throttle);
bool sendMessage(const std::string& filename, bool throttle);
private:
std::string _url;
@ -213,7 +213,7 @@ namespace ix
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now - _start);
_ms = milliseconds.count();
spdlog::info("{} completed in {}", _description, _ms);
spdlog::info("{} completed in {} ms", _description, _ms);
_reported = true;
}
@ -230,7 +230,7 @@ namespace ix
bool _reported;
};
void WebSocketSender::sendMessage(const std::string& filename, bool throttle)
bool WebSocketSender::sendMessage(const std::string& filename, bool throttle)
{
std::vector<uint8_t> content;
{
@ -251,7 +251,7 @@ namespace ix
MsgPack msg(pdu);
Bench bench("Sending file through websocket");
_webSocket.sendBinary(msg.dump(), [throttle](int current, int total) -> bool {
auto result = _webSocket.sendBinary(msg.dump(), [throttle](int current, int total) -> bool {
spdlog::info("ws_send: Step {} out of {}", current, total);
if (throttle)
@ -263,6 +263,12 @@ namespace ix
return true;
});
if (!result.success)
{
spdlog::error("ws_send: Error sending file.");
return false;
}
do
{
size_t bufferedAmount = _webSocket.bufferedAmount();
@ -277,6 +283,8 @@ namespace ix
auto transferRate = 1000 * content.size() / duration;
transferRate /= (1024 * 1024);
spdlog::info("ws_send: Send transfer rate: {} MB/s", transferRate);
return true;
}
void wsSend(const std::string& url,
@ -291,11 +299,12 @@ namespace ix
webSocketSender.waitForConnection();
spdlog::info("ws_send: Sending...");
webSocketSender.sendMessage(path, throttle);
if (webSocketSender.sendMessage(path, throttle))
{
webSocketSender.waitForAck();
spdlog::info("ws_send: Done !");
}
webSocketSender.waitForAck();
spdlog::info("ws_send: Done !");
webSocketSender.stop();
}