From dc6f11f07b38bf6b7a28f6a75876e203cf2d67c6 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 13 Sep 2017 15:51:12 +0100 Subject: [PATCH] Remove socket_helpers.h - serialiser can now write directly to socket --- renderdoc/CMakeLists.txt | 1 - renderdoc/core/remote_server.cpp | 1 - renderdoc/core/replay_proxy.h | 1 - renderdoc/core/socket_helpers.h | 254 ---------------------------- renderdoc/core/target_control.cpp | 1 - renderdoc/renderdoc.vcxproj | 1 - renderdoc/renderdoc.vcxproj.filters | 3 - 7 files changed, 262 deletions(-) delete mode 100644 renderdoc/core/socket_helpers.h diff --git a/renderdoc/CMakeLists.txt b/renderdoc/CMakeLists.txt index bed4db459..987a16a8f 100644 --- a/renderdoc/CMakeLists.txt +++ b/renderdoc/CMakeLists.txt @@ -92,7 +92,6 @@ set(sources core/plugins.h core/resource_manager.cpp core/resource_manager.h - core/socket_helpers.h data/hlsl/debugcbuffers.h data/glsl/debuguniforms.h data/glsl/vk_texsample.h diff --git a/renderdoc/core/remote_server.cpp b/renderdoc/core/remote_server.cpp index 7a35c6bdf..8bae59291 100644 --- a/renderdoc/core/remote_server.cpp +++ b/renderdoc/core/remote_server.cpp @@ -33,7 +33,6 @@ #include "serialise/serialiser.h" #include "strings/string_utils.h" #include "replay_proxy.h" -#include "socket_helpers.h" using std::pair; diff --git a/renderdoc/core/replay_proxy.h b/renderdoc/core/replay_proxy.h index c58bfcce8..6749b8ca3 100644 --- a/renderdoc/core/replay_proxy.h +++ b/renderdoc/core/replay_proxy.h @@ -28,7 +28,6 @@ #include "os/os_specific.h" #include "replay/replay_driver.h" #include "serialise/serialiser.h" -#include "socket_helpers.h" enum ReplayProxyPacket { diff --git a/renderdoc/core/socket_helpers.h b/renderdoc/core/socket_helpers.h deleted file mode 100644 index 67dc4c9a3..000000000 --- a/renderdoc/core/socket_helpers.h +++ /dev/null @@ -1,254 +0,0 @@ -/****************************************************************************** - * The MIT License (MIT) - * - * Copyright (c) 2015-2017 Baldur Karlsson - * Copyright (c) 2014 Crytek - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ - -#pragma once - -inline uint32_t RecvPacket(Network::Socket *sock) -{ - if(sock == NULL) - return ~0U; - - uint32_t t = 0; - if(!sock->RecvDataBlocking(&t, sizeof(t))) - return ~0U; - - return t; -} - -template -bool RecvPacket(Network::Socket *sock, PacketTypeEnum &type, vector &payload) -{ - if(sock == NULL) - return false; - - uint32_t t = 0; - if(!sock->RecvDataBlocking(&t, sizeof(t))) - return false; - - uint32_t payloadLength = 0; - if(!sock->RecvDataBlocking(&payloadLength, sizeof(payloadLength))) - return false; - - if(payloadLength > 0) - { - payload.resize(payloadLength); - - if(!sock->RecvDataBlocking(&payload[0], payloadLength)) - return false; - } - - type = (PacketTypeEnum)t; - - return true; -} - -template -bool RecvPacket(Network::Socket *sock, PacketTypeEnum &type, Serialiser **ser) -{ - if(sock == NULL) - return false; - - vector payload; - bool ret = RecvPacket(sock, type, payload); - if(!ret) - { - *ser = NULL; - return false; - } - - *ser = new Serialiser(payload.size(), &payload[0], false); - - return true; -} - -template -bool SendPacket(Network::Socket *sock, PacketTypeEnum type) -{ - if(sock == NULL) - return false; - - uint32_t t = (uint32_t)type; - if(!sock->SendDataBlocking(&t, sizeof(t))) - return false; - - return true; -} - -template -bool SendPacket(Network::Socket *sock, PacketTypeEnum type, const Serialiser &ser) -{ - if(sock == NULL) - return false; - - uint32_t t = (uint32_t)type; - if(!sock->SendDataBlocking(&t, sizeof(t))) - return false; - - uint32_t payloadLength = ser.GetOffset() & 0xffffffff; - if(!sock->SendDataBlocking(&payloadLength, sizeof(payloadLength))) - return false; - - if(!sock->SendDataBlocking(ser.GetRawPtr(0), payloadLength)) - return false; - - return true; -} - -template -bool RecvChunkedFile(Network::Socket *sock, PacketTypeEnum packetType, const char *logfile, - Serialiser *&ser, float *progress) -{ - if(sock == NULL) - return false; - - vector payload; - PacketTypeEnum type; - - if(!RecvPacket(sock, type, payload)) - return false; - - if(type != packetType) - return false; - - ser = new Serialiser(payload.size(), &payload[0], false); - - uint64_t fileLength; - uint32_t bufLength; - uint32_t numBuffers; - - uint64_t sz = ser->GetSize(); - ser->SetOffset(sz - sizeof(uint64_t) - sizeof(uint32_t) * 2); - - ser->Serialise("", fileLength); - ser->Serialise("", bufLength); - ser->Serialise("", numBuffers); - - ser->SetOffset(0); - - FILE *f = FileIO::fopen(logfile, "wb"); - - if(f == NULL) - { - return false; - } - - if(progress) - *progress = 0.0001f; - - for(uint32_t i = 0; i < numBuffers; i++) - { - if(!RecvPacket(sock, type, payload)) - { - FileIO::fclose(f); - return false; - } - - if(type != packetType) - { - FileIO::fclose(f); - return false; - } - - FileIO::fwrite(&payload[0], 1, payload.size(), f); - - if(progress) - *progress = float(i + 1) / float(numBuffers); - } - - FileIO::fclose(f); - - return true; -} - -template -bool SendChunkedFile(Network::Socket *sock, PacketTypeEnum type, const char *logfile, - Serialiser &ser, float *progress) -{ - if(sock == NULL) - return false; - - FILE *f = FileIO::fopen(logfile, "rb"); - - if(f == NULL) - { - return false; - } - - FileIO::fseek64(f, 0, SEEK_END); - uint64_t fileLen = FileIO::ftell64(f); - FileIO::fseek64(f, 0, SEEK_SET); - - uint32_t bufLen = (uint32_t)RDCMIN((uint64_t)4 * 1024 * 1024, fileLen); - uint64_t n = fileLen / (uint64_t)bufLen; - uint32_t numBufs = (uint32_t)n; - if(fileLen % (uint64_t)bufLen > 0) - numBufs++; // last remaining buffer - - ser.Serialise("", fileLen); - ser.Serialise("", bufLen); - ser.Serialise("", numBufs); - - if(!SendPacket(sock, type, ser)) - { - FileIO::fclose(f); - return false; - } - - byte *buf = new byte[bufLen]; - - uint32_t t = (uint32_t)type; - - if(progress) - *progress = 0.0001f; - - for(uint32_t i = 0; i < numBufs; i++) - { - uint32_t payloadLength = RDCMIN(bufLen, (uint32_t)(fileLen & 0xffffffff)); - - FileIO::fread(buf, 1, payloadLength, f); - - if(!sock->SendDataBlocking(&t, sizeof(t)) || - !sock->SendDataBlocking(&payloadLength, sizeof(payloadLength)) || - !sock->SendDataBlocking(buf, payloadLength)) - { - break; - } - - fileLen -= payloadLength; - if(progress) - *progress = float(i + 1) / float(numBufs); - } - - delete[] buf; - - FileIO::fclose(f); - - if(fileLen != 0) - { - return false; - } - - return true; -} diff --git a/renderdoc/core/target_control.cpp b/renderdoc/core/target_control.cpp index f09c6085d..62a11ea18 100644 --- a/renderdoc/core/target_control.cpp +++ b/renderdoc/core/target_control.cpp @@ -29,7 +29,6 @@ #include "jpeg-compressor/jpgd.h" #include "os/os_specific.h" #include "serialise/serialiser.h" -#include "socket_helpers.h" enum PacketType { diff --git a/renderdoc/renderdoc.vcxproj b/renderdoc/renderdoc.vcxproj index 6f502c6c2..b2f95a02a 100644 --- a/renderdoc/renderdoc.vcxproj +++ b/renderdoc/renderdoc.vcxproj @@ -162,7 +162,6 @@ - diff --git a/renderdoc/renderdoc.vcxproj.filters b/renderdoc/renderdoc.vcxproj.filters index e11f2a167..8a359dce0 100644 --- a/renderdoc/renderdoc.vcxproj.filters +++ b/renderdoc/renderdoc.vcxproj.filters @@ -156,9 +156,6 @@ Common\Maths - - Core\networking - Core\networking