From 9e28495cb7309ea07431a02838eccbbb46841daa Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 9 Jun 2018 19:18:41 +0200 Subject: Fix send not working, allow sending 0 bytes --- src/BootstrapConnection.cpp | 2 +- src/DirectConnection.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/BootstrapConnection.cpp b/src/BootstrapConnection.cpp index fffb332..361f13a 100644 --- a/src/BootstrapConnection.cpp +++ b/src/BootstrapConnection.cpp @@ -91,7 +91,7 @@ namespace sibs throw PubsubKeyAlreadyListeningException(""); listenCallbackFuncs[pubsubKey] = callbackFunc; } - connections.send(serverPeer, std::make_shared>(pubsubKey.data.data(), pubsubKey.data.data()), + connections.send(serverPeer, std::make_shared>(pubsubKey.data.begin(), pubsubKey.data.end()), [](PubSubResult result, const std::string &resultStr) { Log::debug("BootstrapConnection::listen: PubSubResult: %d, result string: %s", result, resultStr.c_str()); diff --git a/src/DirectConnection.cpp b/src/DirectConnection.cpp index 713b3ac..8e60c47 100644 --- a/src/DirectConnection.cpp +++ b/src/DirectConnection.cpp @@ -126,7 +126,7 @@ namespace sibs std::thread([peer, data, sendDataCallbackFunc]() { usize sentSizeTotal = 0; - while(sentSizeTotal < data->size()) + while(sentSizeTotal < data->size() || data->size() == 0) { int sentSize = UDT::send(peer->socket, (char*)data->data() + sentSizeTotal, data->size() - sentSizeTotal, 0); if(sentSize == UDT::ERROR) @@ -135,6 +135,8 @@ namespace sibs sendDataCallbackFunc(PubSubResult::ERROR, UDT::getlasterror_desc()); } sentSizeTotal += sentSize; + if(data->size() == 0) + break; } if(sendDataCallbackFunc) sendDataCallbackFunc(PubSubResult::OK, ""); -- cgit v1.2.3