mirror of
https://github.com/wiiu-env/wiiload_plugin.git
synced 2024-11-25 12:06:52 +01:00
Restart the wiiload server on connection issues
This commit is contained in:
parent
3559ac4049
commit
ca47e10a0c
@ -4,13 +4,13 @@
|
|||||||
#include "utils/net.h"
|
#include "utils/net.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <coreinit/cache.h>
|
||||||
#include <coreinit/debug.h>
|
#include <coreinit/debug.h>
|
||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
#include <coreinit/title.h>
|
#include <coreinit/title.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <rpxloader/rpxloader.h>
|
#include <rpxloader/rpxloader.h>
|
||||||
#include <sysapp/launch.h>
|
#include <sysapp/launch.h>
|
||||||
#include <sysapp/title.h>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <wups_backend/PluginUtils.h>
|
#include <wups_backend/PluginUtils.h>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
@ -30,18 +30,16 @@ TcpReceiver::TcpReceiver(int32_t port)
|
|||||||
|
|
||||||
TcpReceiver::~TcpReceiver() {
|
TcpReceiver::~TcpReceiver() {
|
||||||
exitRequested = true;
|
exitRequested = true;
|
||||||
|
OSMemoryBarrier();
|
||||||
if (serverSocket >= 0) {
|
if (serverSocket >= 0) {
|
||||||
shutdown(serverSocket, SHUT_RDWR);
|
cleanupSocket();
|
||||||
close(serverSocket);
|
|
||||||
serverSocket = -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TcpReceiver::executeThread() {
|
bool TcpReceiver::createSocket() {
|
||||||
serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||||
if (serverSocket < 0) {
|
if (serverSocket < 0) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t enable = 1;
|
uint32_t enable = 1;
|
||||||
@ -53,48 +51,62 @@ void TcpReceiver::executeThread() {
|
|||||||
bindAddress.sin_port = serverPort;
|
bindAddress.sin_port = serverPort;
|
||||||
bindAddress.sin_addr.s_addr = INADDR_ANY;
|
bindAddress.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
|
||||||
socklen_t len;
|
|
||||||
int32_t ret;
|
int32_t ret;
|
||||||
if ((ret = bind(serverSocket, (struct sockaddr *) &bindAddress, 16)) < 0) {
|
if ((ret = bind(serverSocket, (struct sockaddr *) &bindAddress, 16)) < 0) {
|
||||||
shutdown(serverSocket, SHUT_RDWR);
|
cleanupSocket();
|
||||||
close(serverSocket);
|
return false;
|
||||||
serverSocket = -1;
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = listen(serverSocket, 1)) < 0) {
|
if ((ret = listen(serverSocket, 1)) < 0) {
|
||||||
|
cleanupSocket();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpReceiver::cleanupSocket() {
|
||||||
|
if (serverSocket >= 0) {
|
||||||
shutdown(serverSocket, SHUT_RDWR);
|
shutdown(serverSocket, SHUT_RDWR);
|
||||||
close(serverSocket);
|
close(serverSocket);
|
||||||
serverSocket = -1;
|
serverSocket = -1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct sockaddr_in clientAddr {};
|
void TcpReceiver::executeThread() {
|
||||||
memset(&clientAddr, 0, sizeof(clientAddr));
|
socklen_t len;
|
||||||
|
|
||||||
while (!exitRequested) {
|
while (!exitRequested) {
|
||||||
len = 16;
|
if (serverSocket < 0) {
|
||||||
|
if (!createSocket()) {
|
||||||
|
DEBUG_FUNCTION_LINE_WARN("Starting the wiiload server failed. Check the network connection.");
|
||||||
|
OSSleepTicks(OSSecondsToTicks(5));
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
struct sockaddr_in clientAddr {};
|
||||||
|
memset(&clientAddr, 0, sizeof(clientAddr));
|
||||||
|
|
||||||
|
len = 16;
|
||||||
|
DEBUG_FUNCTION_LINE("Waiting for wiiload connection");
|
||||||
int32_t clientSocket = accept(serverSocket, (struct sockaddr *) &clientAddr, &len);
|
int32_t clientSocket = accept(serverSocket, (struct sockaddr *) &clientAddr, &len);
|
||||||
if (clientSocket >= 0) {
|
if (clientSocket >= 0) {
|
||||||
uint32_t ipAddress = clientAddr.sin_addr.s_addr;
|
uint32_t ipAddress = clientAddr.sin_addr.s_addr;
|
||||||
//serverReceiveStart(this, ipAddress);
|
int32_t result = loadToMemory(clientSocket, ipAddress);
|
||||||
int32_t result = loadToMemory(clientSocket, ipAddress);
|
|
||||||
//serverReceiveFinished(this, ipAddress, result);
|
|
||||||
close(clientSocket);
|
close(clientSocket);
|
||||||
|
|
||||||
|
|
||||||
if (result >= 0) {
|
if (result >= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DEBUG_FUNCTION_LINE_ERR("Server socket accept failed socket: %i errno: %d", clientSocket, errno);
|
if (!exitRequested) {
|
||||||
OSSleepTicks(OSMicrosecondsToTicks(100000));
|
DEBUG_FUNCTION_LINE_WARN("Error accepting the socket");
|
||||||
|
cleanupSocket();
|
||||||
|
OSSleepTicks(OSSecondsToTicks(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cleanupSocket();
|
||||||
shutdown(serverSocket, SHUT_RDWR);
|
DEBUG_FUNCTION_LINE("Stopping wiiload server.");
|
||||||
close(serverSocket);
|
|
||||||
serverSocket = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
|
||||||
|
@ -24,6 +24,9 @@ public:
|
|||||||
private:
|
private:
|
||||||
void executeThread() override;
|
void executeThread() override;
|
||||||
|
|
||||||
|
bool createSocket();
|
||||||
|
void cleanupSocket();
|
||||||
|
|
||||||
static int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
|
static int32_t loadToMemory(int32_t clientSocket, uint32_t ipAddress);
|
||||||
|
|
||||||
bool exitRequested;
|
bool exitRequested;
|
||||||
|
Loading…
Reference in New Issue
Block a user