From bd806241fdf4c6ad94f3b11f84dcf15affcefbd0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 17 Oct 2013 17:01:15 -0700 Subject: [PATCH] don't attempt to send in UDPSocket with NULL destAddress --- libraries/shared/src/UDPSocket.cpp | 22 ++++++++++++------- .../voxel-server-library/src/VoxelServer.cpp | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libraries/shared/src/UDPSocket.cpp b/libraries/shared/src/UDPSocket.cpp index 73849847e4..1318fbc4a5 100644 --- a/libraries/shared/src/UDPSocket.cpp +++ b/libraries/shared/src/UDPSocket.cpp @@ -265,16 +265,22 @@ bool UDPSocket::receive(sockaddr* recvAddress, void* receivedData, ssize_t* rece } int UDPSocket::send(sockaddr* destAddress, const void* data, size_t byteLength) const { - // send data via UDP - int sent_bytes = sendto(handle, (const char*)data, byteLength, - 0, (sockaddr *) destAddress, sizeof(sockaddr_in)); - - if (sent_bytes != byteLength) { - qDebug("Failed to send packet: %s\n", strerror(errno)); - return false; + if (destAddress) { + // send data via UDP + int sent_bytes = sendto(handle, (const char*)data, byteLength, + 0, (sockaddr *) destAddress, sizeof(sockaddr_in)); + + if (sent_bytes != byteLength) { + qDebug("Failed to send packet: %s\n", strerror(errno)); + return false; + } + + return sent_bytes; + } else { + qDebug("UDPSocket send called with NULL destination address - Likely a node with no active socket.\n"); + return 0; } - return sent_bytes; } int UDPSocket::send(const char* destAddress, int destPort, const void* data, size_t byteLength) const { diff --git a/libraries/voxel-server-library/src/VoxelServer.cpp b/libraries/voxel-server-library/src/VoxelServer.cpp index 188a2c7e05..3bacfd8462 100644 --- a/libraries/voxel-server-library/src/VoxelServer.cpp +++ b/libraries/voxel-server-library/src/VoxelServer.cpp @@ -454,7 +454,7 @@ void VoxelServer::run() { Node* node = nodeList->nodeWithUUID(nodeUUID); if (node) { - NodeList::getInstance()->updateNodeWithData(node, &senderAddress, packetData, packetLength); + nodeList->updateNodeWithData(node, &senderAddress, packetData, packetLength); VoxelNodeData* nodeData = (VoxelNodeData*) node->getLinkedData(); if (nodeData && !nodeData->isVoxelSendThreadInitalized()) {