Changeset 244 in flair-src for trunk/tools/FlairGCS/src/Manager.cpp


Ignore:
Timestamp:
May 24, 2018, 11:45:33 AM (4 years ago)
Author:
Sanahuja Guillaume
Message:

modifs segfault when closing connection

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/FlairGCS/src/Manager.cpp

    r234 r244  
    3737  qRegisterMetaType<QModelIndex>("QModelIndex"); // pour le file ui??
    3838  this->name = name;
    39 //fprintf(stderr,"Manager %x\n",thread());
     39//ffprintf(stderr,stderr,"Manager %x\n",thread());
    4040  setWindowTitle(name);
    4141
     
    8888
    8989  if (UDT::ERROR == UDT::bind(serv, (sockaddr *)&my_addr, sizeof(my_addr))) {
    90     printf("bind error, %s\n", UDT::getlasterror().getErrorMessage());
     90    fprintf(stderr,"bind error, %s\n", UDT::getlasterror().getErrorMessage());
    9191  }
    9292
    9393  if (UDT::ERROR == UDT::listen(serv, 1)) {
    94     printf("listen error, %s\n", UDT::getlasterror().getErrorMessage());
     94    fprintf(stderr,"listen error, %s\n", UDT::getlasterror().getErrorMessage());
    9595  }
    9696
     
    101101
    102102Manager::~Manager() {
    103   printf("%i\n",udtSockets.count());
    104103  for (int i = 0; i < udtSockets.count(); i++) {
    105104    udtSockets.at(i)->kill();
     
    109108  // delete main_layout;
    110109  UDT::cleanup();
    111   printf("ok\n");
    112110}
    113111
     
    120118  if (UDT::INVALID_SOCK ==(socket = UDT::accept(serv, (sockaddr *)&their_addr, &namelen))) {
    121119    if (UDT::getlasterror().getErrorCode() != 6002)
    122       printf("accept error: %s, code %i\n", UDT::getlasterror().getErrorMessage(),UDT::getlasterror().getErrorCode());
     120      fprintf(stderr,"accept error: %s, code %i\n", UDT::getlasterror().getErrorMessage(),UDT::getlasterror().getErrorCode());
    123121    return;
    124122  } else {
    125123    QString name=QString("%1:%2").arg(inet_ntoa(their_addr.sin_addr)).arg(their_addr.sin_port);
    126     printf("connected to %s\n",name.toLocal8Bit().constData());
     124    fprintf(stderr,"connected to %s\n",name.toLocal8Bit().constData());
    127125   
    128126    QThread *thread = new QThread(this);
     
    148146  connect(udtSocket, SIGNAL(dataReady(char *, int)), newLayout,SLOT(receive(char *, int)),Qt::BlockingQueuedConnection);
    149147  connect(newLayout, SIGNAL(destroyed(QObject *)), this, SLOT(layoutDestroyed(QObject *)));
     148  connect(udtSocket, SIGNAL(destroyed(QObject *)), this, SLOT(udtSocketDestroyed(QObject *)));
    150149  connect(udtSocket, SIGNAL(destroyed()), newLayout, SLOT(deleteLater()));
    151150 
     
    171170}
    172171
     172void Manager::udtSocketDestroyed(QObject *obj) {
     173  udtSockets.removeOne((UdtSocket *)obj);
     174}
     175
    173176void Manager::layoutDestroyed(QObject *obj) {
    174177  int index = connectionsLayout.indexOf((ConnectionLayout *)obj);
    175178
     179  delete connectionsWidget.at(index);
     180  connectionsWidget.removeAt(index);
     181  connectionsLayout.removeOne((ConnectionLayout *)obj);
     182 
    176183  //tab: avoid having only 1 tab (0, 2 or more)
    177184  if (tabBar->count() > 1) {
     
    179186  }
    180187
    181   delete connectionsWidget.at(index);
    182   connectionsWidget.removeAt(index);
    183   connectionsLayout.removeOne((ConnectionLayout *)obj);
    184 
    185188  if (connectionsLayout.count() == 1) {
    186189    hiddenTabName = tabBar->tabText(0);
     
    191194    status->showMessage("");
    192195  }
     196 
     197 
    193198}
    194199
     
    222227
    223228void Manager::tabBarCurrentChanged(int index) {
     229 
    224230  if (index >= 0) {
    225     connectionsWidget.at(currentTab)->hide();
     231    //if we are coming from layout destroyed
     232    if(currentTab<connectionsLayout.count()) connectionsWidget.at(currentTab)->hide();
    226233    connectionsWidget.at(index)->show();
    227234    currentTab = index;
     
    230237    connectionsWidget.at(0)->show();
    231238  }
    232  
    233239  if (tabBar->count() == 0) {
    234240    status->showMessage(connectionsLayout.at(0)->getUDTStats());
     
    341347    QDomDocument doc("remote_ui_xml");
    342348    connectionsLayout.at(i)->GetUpdateXml((QDomElement *)&doc);
    343     // printf("merge\n%s\n",doc.toString().toLocal8Bit().constData());
     349    // fprintf(stderr,"merge\n%s\n",doc.toString().toLocal8Bit().constData());
    344350
    345351    connectionsLayout.at(i)->XmlToSend(doc);
Note: See TracChangeset for help on using the changeset viewer.