mirror of
https://github.com/wiiu-env/wiiload_plugin.git
synced 2024-11-22 02:29:15 +01:00
Optimize error handling
This commit is contained in:
parent
31dedcfd89
commit
1984203bed
@ -77,9 +77,11 @@ void TcpReceiver::executeThread() {
|
||||
socklen_t len;
|
||||
while (!exitRequested) {
|
||||
if (serverSocket < 0) {
|
||||
if (!createSocket()) {
|
||||
DEBUG_FUNCTION_LINE_WARN("Starting the wiiload server failed. Check the network connection.");
|
||||
OSSleepTicks(OSSecondsToTicks(5));
|
||||
if (!createSocket() && !exitRequested) {
|
||||
if (errno != EBUSY) {
|
||||
DEBUG_FUNCTION_LINE_WARN("Create socket failed %d", errno);
|
||||
}
|
||||
OSSleepTicks(OSMillisecondsToTicks(10));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -87,23 +89,23 @@ void TcpReceiver::executeThread() {
|
||||
memset(&clientAddr, 0, sizeof(clientAddr));
|
||||
|
||||
len = 16;
|
||||
DEBUG_FUNCTION_LINE("Waiting for wiiload connection");
|
||||
int32_t clientSocket = accept(serverSocket, (struct sockaddr *) &clientAddr, &len);
|
||||
if (clientSocket >= 0) {
|
||||
uint32_t ipAddress = clientAddr.sin_addr.s_addr;
|
||||
DEBUG_FUNCTION_LINE("Waiting for wiiload connection");
|
||||
int32_t result = loadToMemory(clientSocket, ipAddress);
|
||||
close(clientSocket);
|
||||
|
||||
if (result >= 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (!exitRequested) {
|
||||
DEBUG_FUNCTION_LINE_WARN("Error accepting the socket");
|
||||
cleanupSocket();
|
||||
OSSleepTicks(OSSecondsToTicks(1));
|
||||
} else if (!exitRequested) {
|
||||
if (errno != EBUSY) {
|
||||
DEBUG_FUNCTION_LINE_WARN("Accept failed %d", errno);
|
||||
}
|
||||
OSSleepTicks(OSMillisecondsToTicks(10));
|
||||
}
|
||||
OSSleepTicks(OSMillisecondsToTicks(1));
|
||||
}
|
||||
cleanupSocket();
|
||||
DEBUG_FUNCTION_LINE("Stopping wiiload server.");
|
||||
|
Loading…
Reference in New Issue
Block a user