diff --git a/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session.cpp b/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session.cpp index 0e85def082752..21a08d85fbd7e 100644 --- a/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session.cpp +++ b/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session.cpp @@ -18,17 +18,17 @@ using namespace PacketReader::IP::TCP; namespace Sessions { - void TCP_Session::PushRecvBuff(std::unique_ptr tcp) + void TCP_Session::PushRecvBuff(ReceivedPayload tcp) { _recvBuff.Enqueue(std::move(tcp)); } - std::unique_ptr TCP_Session::PopRecvBuff() + std::optional TCP_Session::PopRecvBuff() { - std::unique_ptr ret; + ReceivedPayload ret; if (_recvBuff.Dequeue(&ret)) return ret; else - return nullptr; + return std::nullopt; } void TCP_Session::IncrementMyNumber(u32 amount) @@ -159,7 +159,7 @@ namespace Sessions // Clear out _recvBuff while (!_recvBuff.IsQueueEmpty()) { - std::unique_ptr retPay; + ReceivedPayload retPay; if (!_recvBuff.Dequeue(&retPay)) { using namespace std::chrono_literals; diff --git a/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session.h b/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session.h index d374a2ac7d9ef..b928b851dd782 100644 --- a/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session.h +++ b/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session.h @@ -42,7 +42,7 @@ namespace Sessions Bad }; - SimpleQueue> _recvBuff; + SimpleQueue _recvBuff; #ifdef _WIN32 SOCKET client = INVALID_SOCKET; @@ -85,8 +85,8 @@ namespace Sessions private: // Async functions - void PushRecvBuff(std::unique_ptr tcp); - std::unique_ptr PopRecvBuff(); + void PushRecvBuff(ReceivedPayload tcp); + std::optional PopRecvBuff(); void IncrementMyNumber(u32 amount); void UpdateReceivedAckNumber(u32 ack); @@ -104,7 +104,7 @@ namespace Sessions bool ValidateEmptyPacket(PacketReader::IP::TCP::TCP_Packet* tcp, bool ignoreOld = true); // PS2 sent SYN - std::unique_ptr ConnectTCPComplete(bool success); + std::optional ConnectTCPComplete(bool success); bool SendConnect(PacketReader::IP::TCP::TCP_Packet* tcp); bool SendConnected(PacketReader::IP::TCP::TCP_Packet* tcp); @@ -120,7 +120,7 @@ namespace Sessions * S4: PS2 then Sends ACK */ bool CloseByPS2Stage1_2(PacketReader::IP::TCP::TCP_Packet* tcp); - std::unique_ptr CloseByPS2Stage3(); + ReceivedPayload CloseByPS2Stage3(); bool CloseByPS2Stage4(PacketReader::IP::TCP::TCP_Packet* tcp); /* @@ -132,7 +132,7 @@ namespace Sessions * Closing_ClosedByRemoteThenPS2_WaitingForAck * we then check if S3 has been completed */ - std::unique_ptr CloseByRemoteStage1(); + ReceivedPayload CloseByRemoteStage1(); bool CloseByRemoteStage2_ButAfter4(PacketReader::IP::TCP::TCP_Packet* tcp); bool CloseByRemoteStage3_4(PacketReader::IP::TCP::TCP_Packet* tcp); diff --git a/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session_In.cpp b/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session_In.cpp index cbf01ca8720b4..241edb4d6bbc2 100644 --- a/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session_In.cpp +++ b/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session_In.cpp @@ -22,9 +22,9 @@ namespace Sessions { std::optional TCP_Session::Recv() { - std::unique_ptr ret = PopRecvBuff(); - if (ret != nullptr) - return ReceivedPayload{destIP, std::move(ret)}; + std::optional ret = PopRecvBuff(); + if (ret.has_value()) + return ret; switch (state) { @@ -43,9 +43,9 @@ namespace Sessions select(client + 1, nullptr, &writeSet, &exceptSet, &nowait); if (FD_ISSET(client, &writeSet)) - return ReceivedPayload{destIP, ConnectTCPComplete(true)}; + return ConnectTCPComplete(true); if (FD_ISSET(client, &exceptSet)) - return ReceivedPayload{destIP, ConnectTCPComplete(false)}; + return ConnectTCPComplete(false); return std::nullopt; } @@ -153,9 +153,9 @@ namespace Sessions switch (state) { case TCP_State::Connected: - return ReceivedPayload{destIP, CloseByRemoteStage1()}; + return CloseByRemoteStage1(); case TCP_State::Closing_ClosedByPS2: - return ReceivedPayload{destIP, CloseByPS2Stage3()}; + return CloseByPS2Stage3(); default: CloseByRemoteRST(); Console.Error("DEV9: TCP: Remote close occured with invalid TCP state"); @@ -183,7 +183,7 @@ namespace Sessions return std::nullopt; } - std::unique_ptr TCP_Session::ConnectTCPComplete(bool success) + std::optional TCP_Session::ConnectTCPComplete(bool success) { if (success) { @@ -217,7 +217,7 @@ namespace Sessions ret->options.push_back(new TCPopTS(timestampSeconds, lastRecivedTimeStamp)); } - return ret; + return ReceivedPayload{destIP, std::move(ret)}; } else { @@ -232,15 +232,15 @@ namespace Sessions Console.Error("DEV9: TCP: Unkown TCP connection error (getsockopt error: %d)", errno); #endif else - Console.Error("DEV9: TCP: Send error: %d", error); + Console.Error("DEV9: TCP: Connect error: %d", error); state = TCP_State::CloseCompleted; RaiseEventConnectionClosed(); - return nullptr; + return std::nullopt; } } - std::unique_ptr TCP_Session::CloseByPS2Stage3() + ReceivedPayload TCP_Session::CloseByPS2Stage3() { //Console.WriteLn("DEV9: TCP: Remote has closed connection after PS2"); @@ -254,10 +254,10 @@ namespace Sessions //DevCon.WriteLn("myNumberACKed reset"); state = TCP_State::Closing_ClosedByPS2ThenRemote_WaitingForAck; - return ret; + return ReceivedPayload{destIP, std::move(ret)}; } - std::unique_ptr TCP_Session::CloseByRemoteStage1() + ReceivedPayload TCP_Session::CloseByRemoteStage1() { //Console.WriteLn("DEV9: TCP: Remote has closed connection"); @@ -271,6 +271,6 @@ namespace Sessions //DevCon.WriteLn("myNumberACKed reset"); state = TCP_State::Closing_ClosedByRemote; - return ret; + return ReceivedPayload{destIP, std::move(ret)}; } } // namespace Sessions diff --git a/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session_Out.cpp b/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session_Out.cpp index 4769de408b004..b84faa33d2f83 100644 --- a/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session_Out.cpp +++ b/pcsx2/DEV9/Sessions/TCP_Session/TCP_Session_Out.cpp @@ -366,7 +366,7 @@ namespace Sessions std::unique_ptr ret = CreateBasePacket(); ret->SetACK(true); - PushRecvBuff(std::move(ret)); + PushRecvBuff(ReceivedPayload{destIP, std::move(ret)}); } return true; } @@ -524,7 +524,7 @@ namespace Sessions std::unique_ptr ret = CreateBasePacket(); ret->SetACK(true); - PushRecvBuff(std::move(ret)); + PushRecvBuff(ReceivedPayload{destIP, std::move(ret)}); return true; } @@ -591,7 +591,7 @@ namespace Sessions ret->SetACK(true); - PushRecvBuff(std::move(ret)); + PushRecvBuff(ReceivedPayload{destIP, std::move(ret)}); if (myNumberACKed.load()) { @@ -611,7 +611,7 @@ namespace Sessions { std::unique_ptr reterr = CreateBasePacket(); reterr->SetRST(true); - PushRecvBuff(std::move(reterr)); + PushRecvBuff(ReceivedPayload{destIP, std::move(reterr)}); CloseSocket(); state = TCP_State::CloseCompletedFlushBuffer;