[Opentnl-cvs] tnl/test server.cpp,1.4,1.5
Brought to you by:
mark_frohnmayer,
s_alanet
From: Mark F. <mar...@us...> - 2005-05-01 00:30:04
|
Update of /cvsroot/opentnl/tnl/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13600/test Modified Files: server.cpp Log Message: Zeroed out port in unix version of getInterfaceAddresses Fixed BitStream overwrite issue Checked parameters on setFixedRateParams on NetConnection Index: server.cpp =================================================================== RCS file: /cvsroot/opentnl/tnl/test/server.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** server.cpp 21 Feb 2005 07:48:13 -0000 1.4 --- server.cpp 1 May 2005 00:29:55 -0000 1.5 *************** *** 34,39 **** using namespace TNL; //#define TNLTest_SERVER ! #define TNL_TEST_RPC //#define TNL_TEST_PROTOCOL //#define TNL_TEST_RPC --- 34,40 ---- using namespace TNL; + #define TNL_TEST_BANDWIDTH //#define TNLTest_SERVER ! //#define TNL_TEST_RPC //#define TNL_TEST_PROTOCOL //#define TNL_TEST_RPC *************** *** 58,63 **** } gDedicatedServerLogConsumer; ! #if defined(TNLTest_SERVER) // The TNLTest_SERVER test is an example dedicated server for the --- 59,133 ---- } gDedicatedServerLogConsumer; + #if defined(TNL_TEST_BANDWIDTH) + class RPCTestConnection : public EventConnection + { + public: + static U32 totalRecvd; + TNL_DECLARE_RPC(rpcFoo, (ByteBufferPtr buffer)); + TNL_DECLARE_RPC(rpcGotit, (U32 bytes)); + TNL_DECLARE_NETCONNECTION(RPCTestConnection); + void onConnectionEstablished() + { + setFixedRateParameters(20, 20, 150000, 150000); + } + }; ! TNL_IMPLEMENT_NETCONNECTION(RPCTestConnection, NetClassGroupGame, true); ! ! U32 RPCTestConnection::totalRecvd = 0; ! ! TNL_IMPLEMENT_RPC(RPCTestConnection, rpcFoo, (ByteBufferPtr buffer), (buffer), ! NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirAny, 0) ! { ! rpcGotit(buffer->getBufferSize()); ! } ! ! TNL_IMPLEMENT_RPC(RPCTestConnection, rpcGotit, (U32 bytes), (bytes), ! NetClassGroupGameMask, RPCGuaranteedOrdered, RPCDirAny, 0) ! { ! totalRecvd += bytes; ! rpcFoo(new ByteBuffer(bytes)); ! } ! ! int main(int argc, const char **argv) ! { ! TNLLogEnable(LogNetInterface, true); ! NetInterface *clientInterface = new NetInterface(Address(IPProtocol, Address::Any, 25000)); ! NetInterface *serverInterface = new NetInterface(Address(IPProtocol, Address::Any, 25001)); ! ! serverInterface->setAllowsConnections(true); ! serverInterface->setRequiresKeyExchange(true); ! ! serverInterface->setPrivateKey(new AsymmetricKey(32)); ! RPCTestConnection *clientConnection = new RPCTestConnection; ! ! Address addr("IP:127.0.0.1:25001"); ! clientConnection->connect(clientInterface, addr, true, false); ! for(S32 i = 0; i < 400; i++) ! clientConnection->rpcFoo(new ByteBuffer(Random::readI(15, 750))); ! ! U32 startTime = Platform::getRealMilliseconds(); ! U32 currentTime = startTime; ! for(;;) ! { ! U32 time = Platform::getRealMilliseconds(); ! ! if(time - currentTime > 1000) ! { ! currentTime = time; ! logprintf("Rate: %d bytes per second, %d total bytes.", ! RPCTestConnection::totalRecvd * 1000 / (currentTime - startTime), RPCTestConnection::totalRecvd); ! } ! ! serverInterface->checkIncomingPackets(); ! serverInterface->processConnections(); ! clientInterface->checkIncomingPackets(); ! clientInterface->processConnections(); ! Platform::sleep(1); ! } ! ! } ! ! #elif defined(TNLTest_SERVER) // The TNLTest_SERVER test is an example dedicated server for the |