Geistersignal



  • Hallo,
    Ich habe folgendes Problem:
    Eine Slot-Methode(append_connection) einer meiner Klassen(Tconnection_manager) wird zweimal aufgerufen.
    Das erste Mal ist es durchaus gewollt, das zweite Mal, weiß ich nicht woher der Aufruf kam.

    Tconnection_manager ist eine Fabrik und läuft in einem eigenen Thread.

    Die Klasse Tserver_interface ist ein Produkt von Tconnection_manager.
    Objekte dieser Klasse laufen in einem eigenen Thread.
    Sie beinhaltet das Signal void new_incoming_connection(Tconnection_info)vom Typ Qt::QueuedConnection;
    Dieses ist mit der dem Slot append_connection von Tconnection_manager verbunden.

    Ausgelöst wird das Signal in der Methode incoming_connection der Klasse Tserver_tcp_interface welche als friend von Tserver_interface deklariert und von QTCPServer abgeleitet ist.

    void Tserver_tcp_interface::incomingConnection(int socketDescriptor)
    {
    qDebug()<<"incomingConnection reached";
    Tconnection_info connection_info;
    //create a preliminary (vorläufigen) connection_name until the real identification was sent
    connection_info.name = create_connection_name(socketDescriptor);
    connection_info.inbound = true;
    //creating and setting a port will come later
    
    //setting the socket descriptor.This parameter initializises the socket
    connection_info.socket_descriptor = socketDescriptor;
    
    //Setting the channels
    connection_info.channels = this->channels;
    
    //creating the connection
    
    emit server_interface_ptr->new_incoming_connection(connection_info);
    //Request for identification will come later
    
    }
    
    QString  Tserver_tcp_interface::create_connection_name(int socket_descriptor)
    {
    QString str = "inbound_connection_";
    QString descriptor_str;
    descriptor_str.setNum(socket_descriptor);
    str.append(descriptor_str);
    return str;
    }
    
    bool Tconnection_manager::append_connection(Tconnection_info new_connection)
    {
        static int append_count = 0;
        ++append_count;
        qDebug()<<"times in which append_connection executed: "<< append_count;
    
    Tconnection_thread* Pnew_thread;
    Pnew_thread = new(Tconnection_thread);
    new_connection.connection_manager_ptr = this;
    bool success;
    
      if(connections.indexOf(new_connection)!=-1)
      {
      //error connection already exists
      delete Pnew_thread;
      error_handler_ptr->error_connection_already_exists(new_connection);
      return false;
      }
    
    Pnew_thread->init(new_connection);
    
    Pnew_thread->wait(create_connection_delay_time);
    Pnew_thread->start();
    
    if(Pnew_thread->wait_for_objects_created(6000))
    {
         if(Pnew_thread->is_connection_creation_success())
         {
          connection_threads.append(Pnew_thread);
          Tconnection_info temp_connection_info;
          temp_connection_info = Pnew_thread->get_connection_info();
          connections.append(temp_connection_info);
          success = true;
    
         }
         else
         {
         //connection was not initialised correctly
         delete(Pnew_thread)  ;
         success = false;
         }
    
    }
    else
    {
        //Thread supposeably crashed
        delete(Pnew_thread)  ;
        success = false;
    }
    
    qDebug()<<"return from append_connection ";
    return success;
    }
    

    Also mein Problem ist folgendes:
    Wenn eine Socket Verbindung Tserver_tcp_interface::incomingConnection(int socketDescriptor) ankommt wird das Signal: new_incoming_connection(connection_info) ausgelöst.
    Dieses kommt beim Slot append_connection an. append_connection wird auch erfolgreich abgearbeitet. Dann wird append_connecion mit dem selben Parameter erneut ausgelöst.
    Dieses wird dann über die Anweisung error_handler_ptr->error_connection_already_exists(new_connection) beendet.
    Mir ist völlig unklar woher dieser zweite Aufruf kommt:

    - Anhand von new_connection.name weiß ich es kann eigentlich nur aus Tserver_tcp_interface::incomingConnection(int socketDescriptor) kommen.
    Es hat grundsätzlich Namen wie "inbound_connection_17" etc.

    - Die Meldung: qDebug()<<"incomingConnection reached" wird aber nur einmal angezeigt.

    - Auch eine Überwachung mit QSignalSpy ergibt, dass das Signal nur einmal ausgelöst wurde.

    Ist es möglich, dass mit nur einem Auslösen zweimal am Slot ankommt ? Oder sich in der Event Loop dupliziert ?
    Wie kann man den Fehler am Besten aufspüren ?



  • Vielen Dank an alle, die sich Gedanken gemacht haben.
    Ich habe den Fehler gefunden. 🙂



  • Könntest du noch bitte beschreiben, was das problem war. Es könnte jemanden anderen helfen, der eventuell irgendwann auf das gleiche Problem stößt


Anmelden zum Antworten