mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2024-11-25 12:45:17 +00:00
Disable blocking on Recv calls
Adding non-blocking support to emulators prevents them from stalling with this change
This commit is contained in:
parent
2e2909e908
commit
c9b1dfa911
3 changed files with 26 additions and 18 deletions
|
@ -245,30 +245,34 @@ bool Client::startConnection() {
|
||||||
|
|
||||||
Logger::log("Sucessful Connection. Waiting to recieve init packet.\n");
|
Logger::log("Sucessful Connection. Waiting to recieve init packet.\n");
|
||||||
|
|
||||||
|
bool waitingForInitPacket = true;
|
||||||
// wait for client init packet
|
// wait for client init packet
|
||||||
while (true) {
|
while (waitingForInitPacket) {
|
||||||
if (mSocket->RECV()) {
|
if (mSocket->RECV()) {
|
||||||
Packet* curPacket = mSocket->mPacketQueue.popFront();
|
if(!mSocket->mPacketQueue.isEmpty()){
|
||||||
|
|
||||||
if (curPacket->mType == PacketType::CLIENTINIT) {
|
Packet* curPacket = mSocket->mPacketQueue.popFront();
|
||||||
InitPacket* initPacket = (InitPacket*)curPacket;
|
|
||||||
|
|
||||||
Logger::log("Server Max Player Size: %d\n", initPacket->maxPlayers);
|
if (curPacket->mType == PacketType::CLIENTINIT) {
|
||||||
|
InitPacket* initPacket = (InitPacket*)curPacket;
|
||||||
|
|
||||||
maxPuppets = initPacket->maxPlayers - 1;
|
Logger::log("Server Max Player Size: %d\n", initPacket->maxPlayers);
|
||||||
} else {
|
|
||||||
Logger::log("First Packet was not Init!\n");
|
maxPuppets = initPacket->maxPlayers - 1;
|
||||||
mIsConnectionActive = false;
|
} else {
|
||||||
|
Logger::log("First Packet was not Init!\n");
|
||||||
|
mIsConnectionActive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(curPacket);
|
||||||
|
waitingForInitPacket = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(curPacket);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Logger::log("Recieve failed! Stopping Connection.\n");
|
Logger::log("Recieve failed! Stopping Connection.\n");
|
||||||
mIsConnectionActive = false;
|
mIsConnectionActive = false;
|
||||||
|
waitingForInitPacket = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ SocketBase::SocketBase(const char *name)
|
||||||
{
|
{
|
||||||
strcpy(this->sockName, name);
|
strcpy(this->sockName, name);
|
||||||
|
|
||||||
this->sock_flags = 0;
|
this->sock_flags = 0x80;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *SocketBase::getStateChar() {
|
const char *SocketBase::getStateChar() {
|
||||||
|
|
|
@ -82,7 +82,7 @@ bool SocketClient::SEND(Packet *packet) {
|
||||||
if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF)
|
if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF)
|
||||||
Logger::log("Sending packet: %s\n", packetNames[packet->mType]);
|
Logger::log("Sending packet: %s\n", packetNames[packet->mType]);
|
||||||
|
|
||||||
if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), this->sock_flags) > 0)) {
|
if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) {
|
||||||
return true;
|
return true;
|
||||||
} 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);
|
||||||
|
@ -115,9 +115,13 @@ bool SocketClient::RECV() {
|
||||||
if(result > 0) {
|
if(result > 0) {
|
||||||
valread += result;
|
valread += result;
|
||||||
} else {
|
} else {
|
||||||
Logger::log("Header Read Failed! Value: %d Total Read: %d\n", result, valread);
|
if(this->socket_errno==11){
|
||||||
this->closeSocket();
|
return true;
|
||||||
return false;
|
} else {
|
||||||
|
Logger::log("Header Read Failed! Value: %d Total Read: %d\n", result, valread);
|
||||||
|
this->closeSocket();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue