Object::~Object() { if (isOnServer() && m_ID >= OBJECT_ID_POOL_BASE) m_host.m_objectIDs.releaseID(m_ID); m_host.m_objects[m_ID] = nullptr; }
/* * client_init handles multiple threaded connects. It creates * a listener object if either the dual test or tradeoff were * specified. It also creates settings structures for all the * threads and arranges them so they can be managed and started * via the one settings structure that was passed in. */ void client_init( thread_Settings *clients ) { thread_Settings *itr = NULL; thread_Settings *list = NULL; thread_Settings *next = NULL; // Set the first thread to report Settings (except cli side Reverse) setReport( clients ); if (clients->mMode == kTest_Reverse && !isOnServer(clients)) { unsetReport( clients ); } itr = clients; // See if we need to start a listener as well Settings_GenerateListenerSettings( clients, &list ); // Create a multiple report header to handle reporting the // sum of multiple client threads Mutex_Lock( &groupCond ); groupID--; clients->multihdr = InitMulti( clients, groupID ); Mutex_Unlock( &groupCond ); #ifdef HAVE_THREAD if ( list != NULL && !isNAT(list)) { // We have threads and we need to start a listener so // have it ran before the client is launched (unless behind NAT) itr->runNow = list; itr = list; } #endif // For each of the needed threads create a copy of the // provided settings, unsetting the report flag and add // to the list of threads to start for (int i = 1; i < clients->mThreads; i++) { Settings_Copy( clients, &next ); unsetReport( next ); itr->runNow = next; itr = next; } #ifndef HAVE_THREAD if ( list != NULL ) { // We don't have threads and we need to start a listener so // have it ran after the client is finished itr->runNext = list; } #else if ( list != NULL && isNAT(list) ) { // We have threads and we need to start a listener so // have it ran after the client is launched (when behind NAT) itr->runNext = list; } #endif }
/* * server_spawn is responsible for creating a Server class * and launching the server. It is provided as a means for * the C thread subsystem to launch the server C++ object. */ void server_spawn( thread_Settings *thread) { Server *theServer = NULL; if (thread->mMode != kTest_Reverse || !isOnServer(thread)) { // Start up the server theServer = new Server( thread ); // Run the test (nothing serve in server side kTest_Reverse) theServer->Run(); DELETE_PTR( theServer); } }
/* * client_spawn is responsible for creating a Client class * and launching the client. It is provided as a means for * the C thread subsystem to launch the client C++ object. */ void client_spawn( thread_Settings *thread ) { Client *theClient = NULL; // start up the client theClient = new Client( thread ); // Let the server know about our settings theClient->InitiateServer(); if (thread->mMode != kTest_Reverse || isOnServer(thread)) { // Run the test (nothing to send in client side kTest_Reverse) theClient->Run(); } DELETE_PTR( theClient ); }
Object::Object(Host& host, ObjectID ID): m_ID(ID), m_host(host) { if (isOnServer()) { if (m_ID == OBJECT_ID_INVALID) m_ID = m_host.m_objectIDs.allocateID(); } else { if (ID == OBJECT_ID_INVALID) panic("Object on client created with invalid ID"); } auto& objects = m_host.m_objects; if (objects.size() <= m_ID) objects.insert(objects.end(), m_ID * 2 - objects.size(), nullptr); objects[m_ID] = this; }