diff --git a/src/utils/CThread.h b/src/utils/CThread.h index 9748f8d..9f05b48 100644 --- a/src/utils/CThread.h +++ b/src/utils/CThread.h @@ -27,8 +27,8 @@ public: typedef void (*Callback)(CThread *thread, void *arg); //! constructor - explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL) - : pThread(NULL), pThreadStack(NULL), pCallback(callback), pCallbackArg(callbackArg) { + explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = nullptr, void *callbackArg = nullptr) + : pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) { //! save attribute assignment iAttributes = iAttr; //! allocate the thread @@ -43,7 +43,7 @@ public: } //! destructor - virtual ~CThread() { + ~CThread() { shutdownThread(); } @@ -58,36 +58,37 @@ public: //! Thread entry function virtual void executeThread() { - if (pCallback) + if (pCallback) { pCallback(this, pCallbackArg); + } } //! Suspend thread virtual void suspendThread() { - if (isThreadSuspended()) return; - if (pThread) OSSuspendThread(pThread); + if (isThreadSuspended()) { return; } + if (pThread) { OSSuspendThread(pThread); } } //! Resume thread - virtual void resumeThread() { - if (!isThreadSuspended()) return; - if (pThread) OSResumeThread(pThread); + void resumeThread() { + if (!isThreadSuspended()) { return; } + if (pThread) { OSResumeThread(pThread); } } //! Set thread priority virtual void setThreadPriority(int prio) { - if (pThread) OSSetThreadPriority(pThread, prio); + if (pThread) { OSSetThreadPriority(pThread, prio); } } //! Check if thread is suspended [[nodiscard]] virtual BOOL isThreadSuspended() const { - if (pThread) return OSIsThreadSuspended(pThread); + if (pThread) { return OSIsThreadSuspended(pThread); } return false; } //! Check if thread is terminated [[nodiscard]] virtual BOOL isThreadTerminated() const { - if (pThread) return OSIsThreadTerminated(pThread); + if (pThread) { return OSIsThreadTerminated(pThread); } return false; } @@ -97,19 +98,22 @@ public: } //! Shutdown thread - virtual void shutdownThread() { + void shutdownThread() { //! wait for thread to finish if (pThread && !(iAttributes & eAttributeDetach)) { - if (isThreadSuspended()) + if (isThreadSuspended()) { resumeThread(); + } OSJoinThread(pThread, nullptr); } //! free the thread stack buffer - if (pThreadStack) + if (pThreadStack) { free(pThreadStack); - if (pThread) + } + if (pThread) { free(pThread); + } pThread = nullptr; pThreadStack = nullptr; diff --git a/src/utils/TcpReceiver.cpp b/src/utils/TcpReceiver.cpp index e762581..cc6f10e 100644 --- a/src/utils/TcpReceiver.cpp +++ b/src/utils/TcpReceiver.cpp @@ -73,7 +73,6 @@ void TcpReceiver::executeThread() { struct sockaddr_in clientAddr{}; memset(&clientAddr, 0, sizeof(clientAddr)); - int32_t addrlen = sizeof(struct sockaddr); while (!exitRequested) { len = 16; @@ -98,9 +97,6 @@ void TcpReceiver::executeThread() { close(serverSocket); } - -extern bool gDoRelaunch; - int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { DEBUG_FUNCTION_LINE("Loading file from ip %08X", ipAddress); @@ -116,10 +112,7 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { recvwait(clientSocket, (unsigned char *) &fileSizeUnc, sizeof(fileSizeUnc)); // Compressed protocol, read another 4 bytes } - struct in_addr in{}; uint32_t bytesRead = 0; - in.s_addr = ipAddress; - DEBUG_FUNCTION_LINE("transfer start"); auto *loadAddress = (unsigned char *) memalign(0x40, fileSize); @@ -130,7 +123,6 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { // Copy rpl in memory while (bytesRead < fileSize) { - uint32_t blockSize = 0x1000; if (blockSize > (fileSize - bytesRead)) blockSize = fileSize - bytesRead; @@ -270,9 +262,6 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { if (PluginUtils::LoadAndLinkOnRestart(finalList) != 0) { DEBUG_FUNCTION_LINE("Failed to load & link"); - } else { - //gDoRelaunch = true; - //DCFlushRange(&gDoRelaunch, sizeof(gDoRelaunch)); } PluginUtils::destroyPluginContainer(finalList); diff --git a/src/utils/TcpReceiver.h b/src/utils/TcpReceiver.h index 40cb78e..4e9b4be 100644 --- a/src/utils/TcpReceiver.h +++ b/src/utils/TcpReceiver.h @@ -1,5 +1,4 @@ -#ifndef TCP_RECEIVER_H_ -#define TCP_RECEIVER_H_ +#pragma once #include #include @@ -19,13 +18,9 @@ public: explicit TcpReceiver(int32_t port); - ~TcpReceiver() override; - - //sigslot::signal2 serverReceiveStart; - //sigslot::signal3 serverReceiveFinished; + virtual ~TcpReceiver(); private: - void executeThread() override; static int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress); @@ -34,6 +29,3 @@ private: int32_t serverPort; int32_t serverSocket; }; - - -#endif diff --git a/src/utils/utils.c b/src/utils/utils.c index f96117a..52dd764 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -1,5 +1,4 @@ #include -#include #include #include "utils/logger.h"