mirror of https://github.com/PCSX2/pcsx2.git
DEV9: Use ReceivedPayload more in TCP_Session
Instead of shuffling a unique_ptr around Fixes handling of connection failure in ConnectTCPComplete()
This commit is contained in:
parent
e3a666bfe4
commit
0806ca442a
|
@ -18,17 +18,17 @@ using namespace PacketReader::IP::TCP;
|
|||
|
||||
namespace Sessions
|
||||
{
|
||||
void TCP_Session::PushRecvBuff(std::unique_ptr<TCP_Packet> tcp)
|
||||
void TCP_Session::PushRecvBuff(ReceivedPayload tcp)
|
||||
{
|
||||
_recvBuff.Enqueue(std::move(tcp));
|
||||
}
|
||||
std::unique_ptr<TCP_Packet> TCP_Session::PopRecvBuff()
|
||||
std::optional<ReceivedPayload> TCP_Session::PopRecvBuff()
|
||||
{
|
||||
std::unique_ptr<TCP_Packet> 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<TCP_Packet> retPay;
|
||||
ReceivedPayload retPay;
|
||||
if (!_recvBuff.Dequeue(&retPay))
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace Sessions
|
|||
Bad
|
||||
};
|
||||
|
||||
SimpleQueue<std::unique_ptr<PacketReader::IP::TCP::TCP_Packet>> _recvBuff;
|
||||
SimpleQueue<ReceivedPayload> _recvBuff;
|
||||
|
||||
#ifdef _WIN32
|
||||
SOCKET client = INVALID_SOCKET;
|
||||
|
@ -85,8 +85,8 @@ namespace Sessions
|
|||
|
||||
private:
|
||||
// Async functions
|
||||
void PushRecvBuff(std::unique_ptr<PacketReader::IP::TCP::TCP_Packet> tcp);
|
||||
std::unique_ptr<PacketReader::IP::TCP::TCP_Packet> PopRecvBuff();
|
||||
void PushRecvBuff(ReceivedPayload tcp);
|
||||
std::optional<ReceivedPayload> 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<PacketReader::IP::TCP::TCP_Packet> ConnectTCPComplete(bool success);
|
||||
std::optional<ReceivedPayload> 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<PacketReader::IP::TCP::TCP_Packet> 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<PacketReader::IP::TCP::TCP_Packet> CloseByRemoteStage1();
|
||||
ReceivedPayload CloseByRemoteStage1();
|
||||
bool CloseByRemoteStage2_ButAfter4(PacketReader::IP::TCP::TCP_Packet* tcp);
|
||||
bool CloseByRemoteStage3_4(PacketReader::IP::TCP::TCP_Packet* tcp);
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ namespace Sessions
|
|||
{
|
||||
std::optional<ReceivedPayload> TCP_Session::Recv()
|
||||
{
|
||||
std::unique_ptr<TCP_Packet> ret = PopRecvBuff();
|
||||
if (ret != nullptr)
|
||||
return ReceivedPayload{destIP, std::move(ret)};
|
||||
std::optional<ReceivedPayload> 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_Packet> TCP_Session::ConnectTCPComplete(bool success)
|
||||
std::optional<ReceivedPayload> 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_Packet> 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_Packet> 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
|
||||
|
|
|
@ -366,7 +366,7 @@ namespace Sessions
|
|||
std::unique_ptr<TCP_Packet> 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<TCP_Packet> 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<TCP_Packet> reterr = CreateBasePacket();
|
||||
reterr->SetRST(true);
|
||||
PushRecvBuff(std::move(reterr));
|
||||
PushRecvBuff(ReceivedPayload{destIP, std::move(reterr)});
|
||||
|
||||
CloseSocket();
|
||||
state = TCP_State::CloseCompletedFlushBuffer;
|
||||
|
|
Loading…
Reference in New Issue