aboutsummaryrefslogtreecommitdiff
path: root/src/test.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-10-20 23:04:09 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-10-20 23:04:09 +0300
commit4b6138e69b65271b0e568f821a4d1bd285affedd (patch)
tree003fd33f969e5a9bf0bc720bda7f869d1f9c1f45 /src/test.cpp
parentb6fcbc5fbaba4a7faa65f792b16e47a405fa4ebf (diff)
downloadminetest-4b6138e69b65271b0e568f821a4d1bd285affedd.tar.gz
minetest-4b6138e69b65271b0e568f821a4d1bd285affedd.tar.bz2
minetest-4b6138e69b65271b0e568f821a4d1bd285affedd.zip
Improve Connection with threading and some kind of congestion control
Diffstat (limited to 'src/test.cpp')
-rw-r--r--src/test.cpp48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/test.cpp b/src/test.cpp
index 6b9ef4b6f..c1f04b2ef 100644
--- a/src/test.cpp
+++ b/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;