Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1499


Ignore:
Timestamp:
Jun 1, 2008, 1:44:44 PM (16 years ago)
Author:
scheusso
Message:

some speed enhancements regarding to mutexes in enet send/receive mechanisms

Location:
code/branches/network/src/network
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/Client.cc

    r1494 r1499  
    153153    if(!isConnected)
    154154      return false;
    155     if(client_connection.addPacket(pck_gen.chatMessage( message.c_str() )))
    156       return client_connection.sendPackets();
     155    return client_connection.addPacket(pck_gen.chatMessage( message.c_str() ));
     156      //return client_connection.sendPackets();
    157157    // send packets
    158158    return false;
    159   }
    160 
    161 
    162   /**
    163   * Sends out all the packets queued by addXXX
    164   */
    165   bool Client::sendPackets(){
    166     if(!isConnected)
    167       return false;
    168     // send packets
    169     client_connection.sendPackets();
    170     return true;
    171159  }
    172160
     
    215203    }// otherwise we had no gamestate to load
    216204    gamestate.cleanup();
    217     if(!client_connection.sendPackets())
    218       COUT(3) << "Problem sending packets to server" << std::endl;
     205    /*if(!client_connection.sendPackets())
     206      COUT(3) << "Problem sending packets to server" << std::endl;*/
    219207    return;
    220208  }
  • code/branches/network/src/network/Client.h

    r1494 r1499  
    7777    bool sendChat( std::string message );
    7878   
    79     bool sendPackets();
    80    
    8179    int getShipID(){return shipID_;}
    8280    int getClientID(){return clientID_;}
  • code/branches/network/src/network/ClientConnection.cc

    r1494 r1499  
    163163      return;
    164164    }
     165    event = new ENetEvent;
    165166    //main loop
    166167    while(!quit){
    167       event = new ENetEvent;
    168168      //std::cout << "connection loop" << std::endl;
    169169      {
     
    185185        if ( !processData(event) ) COUT(2) << "Current packet was not pushed to packetBuffer -> ev ongoing SegFault" << std::endl;
    186186        COUT(5) << "Cl.Con: processed Data in receiver-thread while loop" << std::endl;
     187        event = new ENetEvent;
    187188        break;
    188189      case ENET_EVENT_TYPE_DISCONNECT:
     
    192193        break;
    193194      case ENET_EVENT_TYPE_NONE:
    194         continue;
     195        //receiverThread_->yield();
     196        usleep(1000);
     197        break;
    195198      }
    196       receiverThread_->yield();
    197199    }
    198200    // now disconnect
  • code/branches/network/src/network/ClientConnection.h

    r1494 r1499  
    5454#define NETWORK_PORT 55556
    5555#define NETWORK_CLIENT_MAX_CONNECTIONS 5
    56 #define NETWORK_CLIENT_TIMEOUT 10
     56#define NETWORK_CLIENT_TIMEOUT 1
    5757#define NETWORK_CLIENT_CHANNELS 2
    5858
  • code/branches/network/src/network/ConnectionManager.cc

    r1497 r1499  
    169169  }
    170170
     171  // we actually dont need that function, because host_service does that for us
    171172  bool ConnectionManager::sendPackets() {
    172173    if(server==NULL)
     
    194195    }
    195196
     197    event = new ENetEvent;
    196198    while(!quit){
    197       event = new ENetEvent;
    198199      { //mutex scope
    199200        boost::recursive_mutex::scoped_lock lock(enet_mutex_);
     
    221222          //if(head_->findClient(&event->peer->address))
    222223            processData(event);
     224            event = new ENetEvent;
    223225//           else
    224226//             COUT(3) << "received a packet from a client we don't know" << std::endl;
     
    228230          //break;
    229231        case ENET_EVENT_TYPE_NONE:
    230           delete event;
    231           receiverThread_->yield();
     232          //receiverThread_->yield();
     233          usleep(1000);
    232234          break;
    233235      }
     
    287289  }
    288290
    289 /**
    290 This function adds a client that connects to the clientlist of the server
    291 NOTE: if you change this, don't forget to change the test function
    292 addClientTest in diffTest.cc since addClient is not good for testing because of syncClassid
    293 */
    294   /*bool ConnectionManager::addClient(ENetEvent *event) {
    295     ClientInformation *temp = head_->insertBack(new ClientInformation);
    296     if(!temp){
    297       COUT(2) << "Conn.Man. could not add client" << std::endl;
    298       return false;
    299     }
    300     if(temp->prev()->getHead()) { //not good if you use anything else than insertBack
    301       temp->prev()->setID(0); //bugfix: not necessary but usefull
    302       temp->setID(1);
    303     }
    304     else
    305       temp->setID(temp->prev()->getID()+1);
    306     temp->setPeer(event->peer);
    307     COUT(3) << "Con.Man: added client id: " << temp->getID() << std::endl;
    308     return true;
    309   }*/
     291
    310292
    311293  int ConnectionManager::getClientID(ENetPeer peer) {
     
    341323      ++it;
    342324    }
    343     sendPackets();
     325    //sendPackets();
    344326    COUT(4) << "syncClassid:\tall synchClassID packets have been sent" << std::endl;
    345327  }
    346328
    347   /*bool ConnectionManager::createClient(int clientID){
    348     ClientInformation *temp = head_->findClient(clientID);
    349     if(!temp){
    350       COUT(2) << "Conn.Man. could not create client with id: " << clientID << std::endl;
    351       return false;
    352     }
    353     COUT(4) << "Con.Man: creating client id: " << temp->getID() << std::endl;
    354     syncClassid(temp->getID());
    355     COUT(4) << "creating spaceship for clientid: " << temp->getID() << std::endl;
    356     // TODO: this is only a hack, until we have a possibility to define default player-join actions
    357     if(!createShip(temp))
    358       COUT(2) << "Con.Man. could not create ship for clientid: " << clientID << std::endl;
    359     else
    360       COUT(3) << "created spaceship" << std::endl;
    361     temp->setSynched(true);
    362     COUT(3) << "sending welcome" << std::endl;
    363     sendWelcome(temp->getID(), temp->getShipID(), true);
    364     return true;
    365   }*/
    366  
    367   /*bool ConnectionManager::removeClient(int clientID){
    368     boost::recursive_mutex::scoped_lock lock(head_->mutex_);
    369     orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::start();
    370     ClientInformation *client = head_->findClient(clientID);
    371     if(!client)
    372       return false;
    373     while(it){
    374       if(it->objectID!=client->getShipID()){
    375         ++it;
    376         continue;
    377       }
    378       orxonox::Iterator<orxonox::SpaceShip> temp=it;
    379       ++it;
    380       delete  *temp;
    381       return head_->removeClient(clientID);
    382     }
    383     return false;
    384   }*/
    385  
    386 /*  bool ConnectionManager::createShip(ClientInformation *client){
    387     if(!client)
    388       return false;
    389     orxonox::Identifier* id = ID("SpaceShip");
    390     if(!id){
    391       COUT(4) << "We could not create the SpaceShip for client: " << client->getID() << std::endl;
    392       return false;
    393     }
    394     orxonox::SpaceShip *no = dynamic_cast<orxonox::SpaceShip *>(id->fabricate());
    395     no->setPosition(orxonox::Vector3(0,0,80));
    396     no->setScale(10);
    397     //no->setYawPitchRoll(orxonox::Degree(-90),orxonox::Degree(-90),orxonox::Degree(0));
    398     no->setMesh("assff.mesh");
    399     no->setMaxSpeed(500);
    400     no->setMaxSideAndBackSpeed(50);
    401     no->setMaxRotation(1.0);
    402     no->setTransAcc(200);
    403     no->setRotAcc(3.0);
    404     no->setTransDamp(75);
    405     no->setRotDamp(1.0);
    406     no->setCamera("cam_"+client->getID());
    407     no->classID = id->getNetworkID();
    408     no->create();
    409    
    410     client->setShipID(no->objectID);
    411     return true;
    412   }*/
     329 
    413330 
    414331  bool ConnectionManager::removeShip(ClientInformation *client){
     
    425342  bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){
    426343    if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){
    427       sendPackets();
     344      //sendPackets();
    428345      return true;
    429346    }else
     
    448365 
    449366 
    450 //   int ConnectionManager::getNumberOfClients() {
    451 //     
    452 //     return clientsShip.size();
    453 //   }
    454  
    455   /*void ConnectionManager::addClientsObjectID( int clientID, int objectID ) {
    456   COUT(4) << "ship of client: " << clientID << ": " << objectID << " mapped" << std::endl;
    457   clientsShip.insert( std::make_pair( clientID, objectID ) );
     367
    458368}
    459 
    460   int ConnectionManager::getClientsShipID( int clientID ) {
    461   return clientsShip[clientID];
    462 }
    463 
    464   int ConnectionManager::getObjectsClientID( int objectID ) {
    465   std::map<int, int>::iterator iter;
    466   for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
    467   if( iter->second == objectID ) return iter->first;
    468 }
    469   return -99;
    470 }
    471 
    472   void ConnectionManager::deleteClientIDReg( int clientID ) {
    473   clientsShip.erase( clientID );
    474 }
    475 
    476   void ConnectionManager::deleteObjectIDReg( int objectID ) {
    477   std::map<int, int>::iterator iter = clientsShip.begin();
    478   for( iter = clientsShip.begin(); iter != clientsShip.end(); iter++ ) {
    479   if( iter->second == objectID ) break;
    480 }
    481   clientsShip.erase( iter->first );
    482 }*/
    483 }
  • code/branches/network/src/network/ConnectionManager.h

    r1494 r1499  
    6262#define NETWORK_PORT 55556
    6363#define NETWORK_MAX_CONNECTIONS 50
    64 #define NETWORK_WAIT_TIMEOUT 10
     64#define NETWORK_WAIT_TIMEOUT 1
    6565
    6666  struct ClientList{
  • code/branches/network/src/network/Server.cc

    r1494 r1499  
    130130    ENetPacket *packet = packet_gen.chatMessage(msg.c_str());
    131131    //std::cout <<"adding packets" << std::endl;
    132     if(connection->addPacketAll(packet))
    133     //std::cout <<"added packets" << std::endl;
    134       return connection->sendPackets();
    135     else
    136       return false;
     132    return connection->addPacketAll(packet);
    137133  }
    138134
     
    145141    ENetPacket *packet = packet_gen.chatMessage(msg);
    146142    COUT(4) <<"Server: adding Packets" << std::endl;
    147     connection->addPacketAll(packet);
    148     //std::cout <<"added packets" << std::endl;
    149     if (connection->sendPackets()){
    150       COUT(4) << "Server: Sucessfully" << std::endl;
    151       return true;
    152     }
    153     return false;
     143    return connection->addPacketAll(packet);
    154144  }
    155145
     
    184174      if(!event)
    185175        continue;
     176      assert(event->type != ENET_EVENT_TYPE_NONE);
    186177      switch( event->type ) {
    187178      case ENET_EVENT_TYPE_CONNECT:
     
    265256      delete gs;
    266257    }
    267     if(added) {
     258    /*if(added) {
    268259      //std::cout << "send gamestates from server.cc in sendGameState" << std::endl;
    269260      return connection->sendPackets();
    270     }
    271     COUT(5) << "Server: had no gamestates to send" << std::endl;
    272     return false;
     261    }*/
     262    //COUT(5) << "Server: had no gamestates to send" << std::endl;
     263    return true;
    273264  }
    274265
Note: See TracChangeset for help on using the changeset viewer.