BBA/HLE: Handle connection error
This commit is contained in:
parent
73aa8c50a2
commit
c0fd59adfd
|
@ -269,8 +269,24 @@ CEXIETHERNET::BuiltInBBAInterface::TryGetDataFromSocket(StackRef* ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
case IPPROTO_TCP:
|
case IPPROTO_TCP:
|
||||||
if (!ref->tcp_socket.Connected(ref))
|
switch (ref->tcp_socket.Connected(ref))
|
||||||
|
{
|
||||||
|
case BbaTcpSocket::ConnectingState::Error:
|
||||||
|
{
|
||||||
|
// Create the resulting RST ACK packet
|
||||||
|
const Common::TCPPacket result(ref->bba_mac, ref->my_mac, ref->from, ref->to, ref->seq_num,
|
||||||
|
ref->ack_num, TCP_FLAG_RST | TCP_FLAG_ACK);
|
||||||
|
WriteToQueue(result.Build());
|
||||||
|
ref->ip = 0;
|
||||||
|
ref->tcp_socket.disconnect();
|
||||||
|
[[fallthrough]];
|
||||||
|
}
|
||||||
|
case BbaTcpSocket::ConnectingState::None:
|
||||||
|
case BbaTcpSocket::ConnectingState::Connecting:
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
case BbaTcpSocket::ConnectingState::Connected:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
sf::Socket::Status st = sf::Socket::Status::Done;
|
sf::Socket::Status st = sf::Socket::Status::Done;
|
||||||
TcpBuffer* tcp_buffer = nullptr;
|
TcpBuffer* tcp_buffer = nullptr;
|
||||||
|
@ -804,14 +820,11 @@ sf::Socket::Status BbaTcpSocket::GetSockName(sockaddr_in* addr) const
|
||||||
return sf::Socket::Status::Done;
|
return sf::Socket::Status::Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BbaTcpSocket::Connected(StackRef* ref)
|
BbaTcpSocket::ConnectingState BbaTcpSocket::Connected(StackRef* ref)
|
||||||
{
|
{
|
||||||
// Called by ReadThreadHandler's TryGetDataFromSocket
|
// Called by ReadThreadHandler's TryGetDataFromSocket
|
||||||
// TODO: properly handle error state
|
|
||||||
switch (m_connecting_state)
|
switch (m_connecting_state)
|
||||||
{
|
{
|
||||||
case ConnectingState::Connected:
|
|
||||||
return true;
|
|
||||||
case ConnectingState::Connecting:
|
case ConnectingState::Connecting:
|
||||||
{
|
{
|
||||||
const int fd = getHandle();
|
const int fd = getHandle();
|
||||||
|
@ -841,6 +854,7 @@ bool BbaTcpSocket::Connected(StackRef* ref)
|
||||||
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&error), &len) != 0)
|
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&error), &len) != 0)
|
||||||
{
|
{
|
||||||
ERROR_LOG_FMT(SP1, "Failed to get BBA socket error state: {}", Common::StrNetworkError());
|
ERROR_LOG_FMT(SP1, "Failed to get BBA socket error state: {}", Common::StrNetworkError());
|
||||||
|
m_connecting_state = ConnectingState::Error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,7 +899,7 @@ bool BbaTcpSocket::Connected(StackRef* ref)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
return m_connecting_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
BbaUdpSocket::BbaUdpSocket() = default;
|
BbaUdpSocket::BbaUdpSocket() = default;
|
||||||
|
|
|
@ -48,9 +48,6 @@ public:
|
||||||
sf::Socket::Status GetPeerName(sockaddr_in* addr) const;
|
sf::Socket::Status GetPeerName(sockaddr_in* addr) const;
|
||||||
sf::Socket::Status GetSockName(sockaddr_in* addr) const;
|
sf::Socket::Status GetSockName(sockaddr_in* addr) const;
|
||||||
|
|
||||||
bool Connected(StackRef* ref);
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum class ConnectingState
|
enum class ConnectingState
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
|
@ -59,6 +56,9 @@ private:
|
||||||
Error
|
Error
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ConnectingState Connected(StackRef* ref);
|
||||||
|
|
||||||
|
private:
|
||||||
ConnectingState m_connecting_state = ConnectingState::None;
|
ConnectingState m_connecting_state = ConnectingState::None;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue