mirror of
https://github.com/minetest/minetest.git
synced 2025-01-09 06:47:31 +01:00
connection: Remove unused timeout feature
Was only used for a unit test and incorrectly at that.
This commit is contained in:
parent
6608057971
commit
1b8b84bee8
@ -398,8 +398,6 @@ void Client::connect(const Address &address, const std::string &address_name,
|
|||||||
address.print(infostream);
|
address.print(infostream);
|
||||||
infostream << std::endl;
|
infostream << std::endl;
|
||||||
|
|
||||||
// Since we use TryReceive() a timeout here would be ineffective anyway
|
|
||||||
m_con->SetTimeoutMs(0);
|
|
||||||
m_con->Connect(address);
|
m_con->Connect(address);
|
||||||
|
|
||||||
initLocalMapSaving(address, m_address_name, is_local_server);
|
initLocalMapSaving(address, m_address_name, is_local_server);
|
||||||
|
@ -48,7 +48,6 @@ class IConnection
|
|||||||
public:
|
public:
|
||||||
virtual ~IConnection() = default;
|
virtual ~IConnection() = default;
|
||||||
|
|
||||||
virtual void SetTimeoutMs(u32 timeout) = 0;
|
|
||||||
virtual void Serve(Address bind_addr) = 0;
|
virtual void Serve(Address bind_addr) = 0;
|
||||||
virtual void Connect(Address address) = 0;
|
virtual void Connect(Address address) = 0;
|
||||||
virtual bool Connected() = 0;
|
virtual bool Connected() = 0;
|
||||||
@ -56,7 +55,6 @@ public:
|
|||||||
virtual void DisconnectPeer(session_t peer_id) = 0;
|
virtual void DisconnectPeer(session_t peer_id) = 0;
|
||||||
|
|
||||||
virtual bool ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms) = 0;
|
virtual bool ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms) = 0;
|
||||||
virtual void Receive(NetworkPacket *pkt) = 0;
|
|
||||||
bool TryReceive(NetworkPacket *pkt) {
|
bool TryReceive(NetworkPacket *pkt) {
|
||||||
return ReceiveTimeoutMs(pkt, 0);
|
return ReceiveTimeoutMs(pkt, 0);
|
||||||
}
|
}
|
||||||
|
@ -1486,13 +1486,6 @@ bool Connection::ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::Receive(NetworkPacket *pkt)
|
|
||||||
{
|
|
||||||
bool any = ReceiveTimeoutMs(pkt, m_bc_receive_timeout);
|
|
||||||
if (!any)
|
|
||||||
throw NoIncomingDataException("No incoming data");
|
|
||||||
}
|
|
||||||
|
|
||||||
void Connection::Send(session_t peer_id, u8 channelnum,
|
void Connection::Send(session_t peer_id, u8 channelnum,
|
||||||
NetworkPacket *pkt, bool reliable)
|
NetworkPacket *pkt, bool reliable)
|
||||||
{
|
{
|
||||||
|
@ -249,13 +249,11 @@ public:
|
|||||||
|
|
||||||
void putCommand(ConnectionCommandPtr c);
|
void putCommand(ConnectionCommandPtr c);
|
||||||
|
|
||||||
void SetTimeoutMs(u32 timeout) { m_bc_receive_timeout = timeout; }
|
|
||||||
void Serve(Address bind_addr);
|
void Serve(Address bind_addr);
|
||||||
void Connect(Address address);
|
void Connect(Address address);
|
||||||
bool Connected();
|
bool Connected();
|
||||||
void Disconnect();
|
void Disconnect();
|
||||||
bool ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms);
|
bool ReceiveTimeoutMs(NetworkPacket *pkt, u32 timeout_ms);
|
||||||
void Receive(NetworkPacket *pkt);
|
|
||||||
void Send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable);
|
void Send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable);
|
||||||
session_t GetPeerID() const { return m_peer_id; }
|
session_t GetPeerID() const { return m_peer_id; }
|
||||||
Address GetPeerAddress(session_t peer_id);
|
Address GetPeerAddress(session_t peer_id);
|
||||||
@ -317,7 +315,6 @@ private:
|
|||||||
|
|
||||||
// Backwards compatibility
|
// Backwards compatibility
|
||||||
PeerHandler *m_bc_peerhandler;
|
PeerHandler *m_bc_peerhandler;
|
||||||
u32 m_bc_receive_timeout = 0;
|
|
||||||
|
|
||||||
bool m_shutting_down = false;
|
bool m_shutting_down = false;
|
||||||
};
|
};
|
||||||
|
@ -51,12 +51,6 @@ public:
|
|||||||
InvalidIncomingDataException(const char *s) : BaseException(s) {}
|
InvalidIncomingDataException(const char *s) : BaseException(s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class NoIncomingDataException : public BaseException
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NoIncomingDataException(const char *s) : BaseException(s) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SocketException : public BaseException
|
class SocketException : public BaseException
|
||||||
|
@ -551,7 +551,6 @@ void Server::start()
|
|||||||
m_thread->stop();
|
m_thread->stop();
|
||||||
|
|
||||||
// Initialize connection
|
// Initialize connection
|
||||||
m_con->SetTimeoutMs(30);
|
|
||||||
m_con->Serve(m_bind_addr);
|
m_con->Serve(m_bind_addr);
|
||||||
|
|
||||||
// Start thread
|
// Start thread
|
||||||
|
@ -160,6 +160,9 @@ void TestConnection::testHelpers()
|
|||||||
|
|
||||||
void TestConnection::testConnectSendReceive()
|
void TestConnection::testConnectSendReceive()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
constexpr u32 timeout_ms = 100;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Test some real connections
|
Test some real connections
|
||||||
|
|
||||||
@ -210,13 +213,11 @@ void TestConnection::testConnectSendReceive()
|
|||||||
// Client should not have added client yet
|
// Client should not have added client yet
|
||||||
UASSERT(hand_client.count == 0);
|
UASSERT(hand_client.count == 0);
|
||||||
|
|
||||||
try {
|
NetworkPacket pkt;
|
||||||
NetworkPacket pkt;
|
infostream << "** running client.Receive()" << std::endl;
|
||||||
infostream << "** running client.Receive()" << std::endl;
|
if (client.ReceiveTimeoutMs(&pkt, timeout_ms)) {
|
||||||
client.Receive(&pkt);
|
|
||||||
infostream << "** Client received: peer_id=" << pkt.getPeerId()
|
infostream << "** Client received: peer_id=" << pkt.getPeerId()
|
||||||
<< ", size=" << pkt.getSize() << std::endl;
|
<< ", size=" << pkt.getSize() << std::endl;
|
||||||
} catch (con::NoIncomingDataException &e) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client should have added server now
|
// Client should have added server now
|
||||||
@ -227,14 +228,14 @@ void TestConnection::testConnectSendReceive()
|
|||||||
|
|
||||||
sleep_ms(100);
|
sleep_ms(100);
|
||||||
|
|
||||||
try {
|
NetworkPacket pkt1;
|
||||||
NetworkPacket pkt;
|
infostream << "** running server.Receive()" << std::endl;
|
||||||
infostream << "** running server.Receive()" << std::endl;
|
if (server.ReceiveTimeoutMs(&pkt, timeout_ms)) {
|
||||||
server.Receive(&pkt);
|
|
||||||
infostream << "** Server received: peer_id=" << pkt.getPeerId()
|
infostream << "** Server received: peer_id=" << pkt.getPeerId()
|
||||||
<< ", size=" << pkt.getSize()
|
<< ", size=" << pkt.getSize()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} catch (con::NoIncomingDataException &e) {
|
}
|
||||||
|
else {
|
||||||
// No actual data received, but the client has
|
// No actual data received, but the client has
|
||||||
// probably been connected
|
// probably been connected
|
||||||
}
|
}
|
||||||
@ -249,27 +250,23 @@ void TestConnection::testConnectSendReceive()
|
|||||||
//sleep_ms(50);
|
//sleep_ms(50);
|
||||||
|
|
||||||
while (client.Connected() == false) {
|
while (client.Connected() == false) {
|
||||||
try {
|
NetworkPacket pkt;
|
||||||
NetworkPacket pkt;
|
infostream << "** running client.Receive()" << std::endl;
|
||||||
infostream << "** running client.Receive()" << std::endl;
|
if (client.TryReceive(&pkt)) {
|
||||||
client.Receive(&pkt);
|
|
||||||
infostream << "** Client received: peer_id=" << pkt.getPeerId()
|
infostream << "** Client received: peer_id=" << pkt.getPeerId()
|
||||||
<< ", size=" << pkt.getSize() << std::endl;
|
<< ", size=" << pkt.getSize() << std::endl;
|
||||||
} catch (con::NoIncomingDataException &e) {
|
|
||||||
}
|
}
|
||||||
sleep_ms(50);
|
sleep_ms(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep_ms(50);
|
sleep_ms(50);
|
||||||
|
|
||||||
try {
|
NetworkPacket pkt2;
|
||||||
NetworkPacket pkt;
|
infostream << "** running server.Receive()" << std::endl;
|
||||||
infostream << "** running server.Receive()" << std::endl;
|
if (server.ReceiveTimeoutMs(&pkt, timeout_ms)) {
|
||||||
server.Receive(&pkt);
|
|
||||||
infostream << "** Server received: peer_id=" << pkt.getPeerId()
|
infostream << "** Server received: peer_id=" << pkt.getPeerId()
|
||||||
<< ", size=" << pkt.getSize()
|
<< ", size=" << pkt.getSize()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
} catch (con::NoIncomingDataException &e) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -288,7 +285,7 @@ void TestConnection::testConnectSendReceive()
|
|||||||
|
|
||||||
NetworkPacket recvpacket;
|
NetworkPacket recvpacket;
|
||||||
infostream << "** running server.Receive()" << std::endl;
|
infostream << "** running server.Receive()" << std::endl;
|
||||||
server.Receive(&recvpacket);
|
UASSERT(server.ReceiveTimeoutMs(&recvpacket, timeout_ms));
|
||||||
infostream << "** Server received: peer_id=" << pkt.getPeerId()
|
infostream << "** Server received: peer_id=" << pkt.getPeerId()
|
||||||
<< ", size=" << pkt.getSize()
|
<< ", size=" << pkt.getSize()
|
||||||
<< ", data=" << (const char*)pkt.getU8Ptr(0)
|
<< ", data=" << (const char*)pkt.getU8Ptr(0)
|
||||||
@ -338,14 +335,12 @@ void TestConnection::testConnectSendReceive()
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
if (porting::getTimeMs() - timems0 > 5000 || received)
|
if (porting::getTimeMs() - timems0 > 5000 || received)
|
||||||
break;
|
break;
|
||||||
try {
|
NetworkPacket pkt;
|
||||||
NetworkPacket pkt;
|
if (client.ReceiveTimeoutMs(&pkt, timeout_ms)) {
|
||||||
client.Receive(&pkt);
|
|
||||||
size = pkt.getSize();
|
size = pkt.getSize();
|
||||||
peer_id = pkt.getPeerId();
|
peer_id = pkt.getPeerId();
|
||||||
recvdata = pkt.oldForgePacket();
|
recvdata = pkt.oldForgePacket();
|
||||||
received = true;
|
received = true;
|
||||||
} catch (con::NoIncomingDataException &e) {
|
|
||||||
}
|
}
|
||||||
sleep_ms(10);
|
sleep_ms(10);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user