fix: add auto reconnect again

This commit is contained in:
Robin C. Ladiges 2023-09-07 19:30:57 +02:00
parent f27875f65f
commit b4d90d1d85
No known key found for this signature in database
GPG key ID: B494D3DF92661B99

View file

@ -217,8 +217,7 @@ bool SocketClient::send(Packet *packet) {
} else { } else {
Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize);
this->socket_errno = nn::socket::GetLastErrno(); this->socket_errno = nn::socket::GetLastErrno();
this->closeSocket(); return this->tryReconnect();
return false;
} }
return true; return true;
} }
@ -228,8 +227,7 @@ bool SocketClient::recv() {
if (this->socket_log_state != SOCKET_LOG_CONNECTED) { if (this->socket_log_state != SOCKET_LOG_CONNECTED) {
Logger::log("Unable To Receive! Socket Not Connected.\n"); Logger::log("Unable To Receive! Socket Not Connected.\n");
this->socket_errno = nn::socket::GetLastErrno(); this->socket_errno = nn::socket::GetLastErrno();
this->closeSocket(); return this->tryReconnect();
return false;
} }
const int fd_count = 2; const int fd_count = 2;
@ -253,8 +251,7 @@ bool SocketClient::recv() {
} else if (result < 0) { } else if (result < 0) {
Logger::log("Error occurred when polling for packets\n"); Logger::log("Error occurred when polling for packets\n");
this->socket_errno = nn::socket::GetLastErrno(); this->socket_errno = nn::socket::GetLastErrno();
this->closeSocket(); return this->tryReconnect();
return false;
} }
s32 index = -1; s32 index = -1;
@ -297,8 +294,7 @@ bool SocketClient::recvTcp() {
return true; return true;
} else { } else {
Logger::log("Header Read Failed! Value: %d Total Read: %d\n", result, valread); Logger::log("Header Read Failed! Value: %d Total Read: %d\n", result, valread);
this->closeSocket(); return this->tryReconnect();
return false;
} }
} }
} }
@ -306,8 +302,7 @@ bool SocketClient::recvTcp() {
if(valread <= 0) { // if we error'd, close the socket if(valread <= 0) { // if we error'd, close the socket
Logger::log("valread was zero! Disconnecting.\n"); Logger::log("valread was zero! Disconnecting.\n");
this->socket_errno = nn::socket::GetLastErrno(); this->socket_errno = nn::socket::GetLastErrno();
this->closeSocket(); return this->tryReconnect();
return false;
} }
Packet* header = reinterpret_cast<Packet*>(recvBuf); Packet* header = reinterpret_cast<Packet*>(recvBuf);
@ -350,8 +345,7 @@ bool SocketClient::recvTcp() {
} else { } else {
mHeap->free(packetBuf); mHeap->free(packetBuf);
Logger::log("Packet Read Failed! Value: %d\nPacket Size: %d\nPacket Type: %s\n", result, header->mPacketSize, packetNames[header->mType]); Logger::log("Packet Read Failed! Value: %d\nPacket Size: %d\nPacket Type: %s\n", result, header->mPacketSize, packetNames[header->mType]);
this->closeSocket(); return this->tryReconnect();
return false;
} }
} }
@ -380,8 +374,7 @@ bool SocketClient::recvUdp() {
if (valread == 0) { if (valread == 0) {
Logger::log("Udp connection valread was zero. Disconnecting.\n"); Logger::log("Udp connection valread was zero. Disconnecting.\n");
this->closeSocket(); return this->tryReconnect();
return false;
} }
if (valread < headerSize){ if (valread < headerSize){