Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disconnect between forked process and client

Disconnect between forked process and client

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 795 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FrankiPL
    wrote on last edited by
    #1

    Hi all,

    I have QCoreApplication server running on Linux, server fork itself when new connection is made from client
    @
    void Ccbox::incomingConnection(qintptr handle) {
    qDebug()<<"Ccbox::incomingConnection";
    pid_t PID=fork();
    if(PID==0) {
    this->close();
    this->startNetwork(handle);
    } else {
    qDebug()<<"Ccbox::incomingConnection another process started";
    }
    }
    @

    "this->close()" is to close child process to listen to port like parent, then pointer "handle" is passed to function that creates socket

    @
    socket=new QSslSocket(this);
    if(!socket->setSocketDescriptor(socketDescriptor)) {
    qDebug() <<"setSocketError:"<<socket->error();
    return;
    }
    qDebug()<<"ssl supported:"<<socket->supportsSsl();
    qDebug()<<"peerAddress:"<<socket->peerAddress();
    socket->addCaCertificates(Zm().sslCA+Zm().sslCACert);
    socket->setPrivateKey(Zm().sslFiles+Zm().sslKey);
    socket->setLocalCertificate(Zm().sslFiles+Zm().sslCert);
    socket->setPeerVerifyMode(QSslSocket::VerifyPeer);
    socket->startServerEncryption();
    @

    this is QSslSocket so some cert options are set and connection is encrypted.

    The problem is that my forked server always ends up in defunct state "[ccbox-demo] <defunct>" after connection is closed between server and client and server makes qApp->quit();

    Connection close is initiated by client with disconnectFromHost and on both ends I can see socket is entering state: QAbstractSocket::UnconnectedState, 5 seconds later forked server makes qApp->quit() and ends up in defunct state.
    I think is what I don't understand is this:
    When I check with lsof command, right after I start client and fork server it shows that both parent and child server are connected to the client:
    @
    ccbox-dem 21347 7u IPv4 2439080 0t0 TCP *:4321 (LISTEN)
    ccbox-dem 21347 8u IPv4 2442399 0t0 TCP localhost:4321->localhost:38669 (ESTABLISHED)
    ccbox-big 21349 10u IPv4 2440519 0t0 TCP localhost:38669->localhost:4321 (ESTABLISHED)
    ccbox-dem 21351 8u IPv4 2442399 0t0 TCP localhost:4321->localhost:38669 (ESTABLISHED)
    @

    and after client is closed parent server is still connected to the client waiting in CLOSE_WAIT state

    @
    ccbox-dem 21347 7u IPv4 2439080 0t0 TCP *:4321 (LISTEN)
    ccbox-dem 21347 8u IPv4 2442399 0t0 TCP localhost:4321->localhost:38669 (CLOSE_WAIT)
    @

    What should I do in parent server to close this connection right after child server has started ? Or is this some other problem? I need to get rid of these defunct processes

    Best Regards
    Marek

    1 Reply Last reply
    0
    • F Offline
      F Offline
      FrankiPL
      wrote on last edited by
      #2

      Really, no one knows anything about it?

      Marek

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved