mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Improve Connection with threading and some kind of congestion control
This commit is contained in:
parent
b6fcbc5fba
commit
4b6138e69b
12 changed files with 1163 additions and 716 deletions
48
src/test.cpp
48
src/test.cpp
|
@ -819,7 +819,10 @@ struct TestConnection
|
|||
|
||||
/*
|
||||
Test some real connections
|
||||
|
||||
NOTE: This mostly tests the legacy interface.
|
||||
*/
|
||||
|
||||
u32 proto_id = 0xad26846a;
|
||||
|
||||
Handler hand_server("server");
|
||||
|
@ -843,11 +846,30 @@ struct TestConnection
|
|||
|
||||
sleep_ms(50);
|
||||
|
||||
// Client should not have added client yet
|
||||
assert(hand_client.count == 0);
|
||||
|
||||
try
|
||||
{
|
||||
u16 peer_id;
|
||||
u8 data[100];
|
||||
infostream<<"** running client.Receive()"<<std::endl;
|
||||
u32 size = client.Receive(peer_id, data, 100);
|
||||
infostream<<"** Client received: peer_id="<<peer_id
|
||||
<<", size="<<size
|
||||
<<std::endl;
|
||||
}
|
||||
catch(con::NoIncomingDataException &e)
|
||||
{
|
||||
}
|
||||
|
||||
// Client should have added server now
|
||||
assert(hand_client.count == 1);
|
||||
assert(hand_client.last_id == 1);
|
||||
// But server should not have added client
|
||||
// Server should not have added client yet
|
||||
assert(hand_server.count == 0);
|
||||
|
||||
sleep_ms(50);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -930,7 +952,7 @@ struct TestConnection
|
|||
}
|
||||
|
||||
u16 peer_id_client = 2;
|
||||
|
||||
#if 0
|
||||
{
|
||||
/*
|
||||
Send consequent packets in different order
|
||||
|
@ -941,13 +963,13 @@ struct TestConnection
|
|||
SharedBuffer<u8> data2 = SharedBufferFromString("Hello2");
|
||||
|
||||
Address client_address =
|
||||
server.GetPeer(peer_id_client)->address;
|
||||
server.GetPeerAddress(peer_id_client);
|
||||
|
||||
infostream<<"*** Sending packets in wrong order (2,1,2)"
|
||||
<<std::endl;
|
||||
|
||||
u8 chn = 0;
|
||||
con::Channel *ch = &server.GetPeer(peer_id_client)->channels[chn];
|
||||
con::Channel *ch = &server.getPeer(peer_id_client)->channels[chn];
|
||||
u16 sn = ch->next_outgoing_seqnum;
|
||||
ch->next_outgoing_seqnum = sn+1;
|
||||
server.Send(peer_id_client, chn, data2, true);
|
||||
|
@ -1004,6 +1026,7 @@ struct TestConnection
|
|||
}
|
||||
assert(got_exception);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
const int datasize = 30000;
|
||||
SharedBuffer<u8> data1(datasize);
|
||||
|
@ -1022,12 +1045,25 @@ struct TestConnection
|
|||
|
||||
server.Send(peer_id_client, 0, data1, true);
|
||||
|
||||
sleep_ms(50);
|
||||
sleep_ms(3000);
|
||||
|
||||
u8 recvdata[datasize + 1000];
|
||||
infostream<<"** running client.Receive()"<<std::endl;
|
||||
u16 peer_id = 132;
|
||||
u16 size = client.Receive(peer_id, recvdata, datasize + 1000);
|
||||
u16 size = 0;
|
||||
bool received = false;
|
||||
u32 timems0 = porting::getTimeMs();
|
||||
for(;;){
|
||||
if(porting::getTimeMs() - timems0 > 5000)
|
||||
break;
|
||||
try{
|
||||
size = client.Receive(peer_id, recvdata, datasize + 1000);
|
||||
received = true;
|
||||
}catch(con::NoIncomingDataException &e){
|
||||
}
|
||||
sleep_ms(10);
|
||||
}
|
||||
assert(received);
|
||||
infostream<<"** Client received: peer_id="<<peer_id
|
||||
<<", size="<<size
|
||||
<<std::endl;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue