From 08f42c08d9e5286ee4483b3f40654c3adf4258c7 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 17 Dec 2015 10:54:32 -0800 Subject: [PATCH 1/2] use a ternary for single assignment --- libraries/embedded-webserver/src/HTTPManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/embedded-webserver/src/HTTPManager.cpp b/libraries/embedded-webserver/src/HTTPManager.cpp index 0b98d52cb1..4c804f2e7b 100644 --- a/libraries/embedded-webserver/src/HTTPManager.cpp +++ b/libraries/embedded-webserver/src/HTTPManager.cpp @@ -147,10 +147,10 @@ bool HTTPManager::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, } // if this is an shtml file just make the MIME type match HTML so browsers aren't confused - auto mimeType = QString { "text/html" }; - if (localFileInfo.suffix() != "shtml") { - mimeType = mimeDatabase.mimeTypeForFile(filePath).name(); - } + // otherwise use the mimeDatabase to look it up + auto mimeType = localFileInfo.suffix() == "shtml" + ? QString { "text/html" } + : mimeDatabase.mimeTypeForFile(filePath).name(); connection->respond(HTTPConnection::StatusCode200, localFileData, qPrintable(mimeType)); From 06e9731fe4f626366f1120b2a85a727b79200ff1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 17 Dec 2015 11:07:36 -0800 Subject: [PATCH 2/2] don't attempt to read an empty or malformed packet --- libraries/networking/src/udt/Socket.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 11f1b043c8..8fb5db3853 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -236,8 +236,14 @@ void Socket::readPendingDatagrams() { auto buffer = std::unique_ptr(new char[packetSizeWithHeader]); // pull the datagram - _udpSocket.readDatagram(buffer.get(), packetSizeWithHeader, - senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); + auto sizeRead = _udpSocket.readDatagram(buffer.get(), packetSizeWithHeader, + senderSockAddr.getAddressPointer(), senderSockAddr.getPortPointer()); + + if (sizeRead <= 0) { + // we either didn't pull anything for this packet or there was an error reading (this seems to trigger + // on windows even if there's not a packet available) + continue; + } auto it = _unfilteredHandlers.find(senderSockAddr); @@ -248,7 +254,7 @@ void Socket::readPendingDatagrams() { it->second(std::move(basePacket)); } - return; + continue; } // check if this was a control packet or a data packet @@ -276,7 +282,7 @@ void Socket::readPendingDatagrams() { packet->getDataSize(), packet->getPayloadSize())) { // the connection indicated that we should not continue processing this packet - return; + continue; } }