Troubleshoot "no more data in UDP packet"

This commit is contained in:
Michael Davidsaver
2019-03-04 17:54:12 -08:00
parent e66893bb38
commit 732fd1f771
2 changed files with 17 additions and 8 deletions

View File

@@ -9,6 +9,8 @@
#include <ws2tcpip.h>
#endif
#include <sstream>
#include <sys/types.h>
#include <cstdio>
@@ -113,6 +115,16 @@ void BlockingUDPTransport::close() {
close(true);
}
void BlockingUDPTransport::ensureData(std::size_t size) {
if (_receiveBuffer.getRemaining() >= size)
return;
std::ostringstream msg;
msg<<"no more data in UDP packet : "
<<_receiveBuffer.getPosition()<<":"<<_receiveBuffer.getLimit()
<<" for "<<size;
throw std::underflow_error(msg.str());
}
void BlockingUDPTransport::close(bool waitForThreadToComplete) {
{
Lock guard(_mutex);
@@ -256,12 +268,12 @@ void BlockingUDPTransport::run() {
processBuffer(thisTransport, fromAddress, &_receiveBuffer);
} catch(std::exception& e) {
LOG(logLevelError,
"an exception caught while in UDP receiveThread at %s:%d: %s",
__FILE__, __LINE__, e.what());
"an exception caught while in UDP receiveThread %s at %s:%d: %s",
_remoteName.c_str(), __FILE__, __LINE__, e.what());
} catch (...) {
LOG(logLevelError,
"unknown exception caught while in UDP receiveThread at %s:%d.",
__FILE__, __LINE__);
"unknown exception caught while in UDP receiveThread %s at %s:%d.",
_remoteName.c_str(), __FILE__, __LINE__);
}
}
} else {

View File

@@ -135,10 +135,7 @@ public:
virtual void close() OVERRIDE FINAL;
virtual void ensureData(std::size_t size) OVERRIDE FINAL {
if (_receiveBuffer.getRemaining() < size)
throw std::underflow_error("no more data in UDP packet");
}
virtual void ensureData(std::size_t size) OVERRIDE FINAL;
virtual void alignData(std::size_t alignment) OVERRIDE FINAL {
_receiveBuffer.align(alignment);