diff --git a/src/main.cpp b/src/main.cpp index 9ee1495..a455068 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include #include "utils/TcpReceiver.h" #include +#include +#include WUPS_PLUGIN_NAME("Wiiload"); WUPS_PLUGIN_DESCRIPTION("Wiiload Server"); @@ -26,9 +28,18 @@ void stopThread() { } } - ON_APPLICATION_END() { DEBUG_FUNCTION_LINE("Kill thread"); stopThread(); } +bool gDoRelaunch __attribute__((section(".data"))) = 0; + +ON_VYSNC() { + // On each frame check if we want to exit. + if(gDoRelaunch){ + SYSRelaunchTitle(0, NULL); + gDoRelaunch = 0; + DCFlushRange(&gDoRelaunch, sizeof(gDoRelaunch)); + } +} diff --git a/src/utils/TcpReceiver.cpp b/src/utils/TcpReceiver.cpp index 505469e..c8dc89b 100644 --- a/src/utils/TcpReceiver.cpp +++ b/src/utils/TcpReceiver.cpp @@ -14,6 +14,7 @@ #include "utils/utils.h" #include #include +#include #define RPX_TEMP_PATH "fs:/vol/external01/wiiu/apps/" #define RPX_TEMP_FILE "fs:/vol/external01/wiiu/apps/temp.rpx" @@ -25,7 +26,7 @@ void _SYSLaunchTitleWithStdArgsInNoSplash(uint64_t, uint32_t); } TcpReceiver::TcpReceiver(int32_t port) - : CThread(CThread::eAttributeAffCore0), exitRequested(false), serverPort(port), serverSocket(-1) { + : CThread(CThread::eAttributeAffCore1, 16,0x20000), exitRequested(false), serverPort(port), serverSocket(-1) { resumeThread(); } @@ -62,8 +63,6 @@ void TcpReceiver::executeThread() { return; } - DEBUG_FUNCTION_LINE(""); - if ((ret = listen(serverSocket, 1)) < 0) { socketclose(serverSocket); return; @@ -84,7 +83,9 @@ void TcpReceiver::executeThread() { socketclose(clientSocket); if (result > 0) + if (result >= 0){ break; + } } else { DEBUG_FUNCTION_LINE("Server socket accept failed %i %d", clientSocket, wiiu_geterrno()); OSSleepTicks(OSMicrosecondsToTicks(100000)); @@ -102,6 +103,7 @@ typedef struct __attribute((packed)) { char path[256]; } LOAD_REQUEST; +extern bool gDoRelaunch; int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { DEBUG_FUNCTION_LINE("Loading file from ip %08X", ipAddress); @@ -260,7 +262,8 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) { PluginUtils::destroyPluginContainer(finalList); } else { PluginUtils::destroyPluginContainer(finalList); - SYSRelaunchTitle(NULL, NULL); + gDoRelaunch = 1; + DCFlushRange(&gDoRelaunch, sizeof(gDoRelaunch)); } free(loadAddress);