Results 1 to 4 of 4

Thread: QProcess: Socket descriptor in argv[]

  1. #1
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QProcess: Socket descriptor in argv[]

    Hi All!

    How send socket descriptor in command prompt arguments on Linux without using fork function?
    I try this:
    Qt Code:
    1. void Server::incomingConnection( int handle )
    2. {
    3. ...
    4.  
    5. QProcess *fork_process = new QProcess( this );
    6. fork_process->setEnvironment( QProcess::systemEnvironment() );
    7. fork_process->setProcessChannelMode( QProcess::MergedChannels );
    8. fork_process->setWorkingDirectory( QCoreApplication::applicationDirPath() );
    9.  
    10. QStringList process_args;
    11. process_args << "SD";
    12. process_args << QString::number( handle );
    13.  
    14. fork_process->start( QCoreApplication::applicationFilePath(), process_args );
    15.  
    16. if (!fork_process->waitForStarted())
    17. {
    18. qDebug() << "fork_process Error: " << fork_process->errorString();
    19.  
    20. delete fork_process;
    21. fork_process = 0;
    22.  
    23. return;
    24. }
    25.  
    26. connect( fork_process, SIGNAL(finished(int,QProcess::ExitStatus)),
    27. this, SLOT(processFinished(int,QProcess::ExitStatus)) );
    28.  
    29. ...
    30. }
    To copy to clipboard, switch view to plain text mode 

    On Windows it work fine, but on Linux I'm get error: Invalid socket descriptor.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess: Socket descriptor in argv[]

    On Unix systems each process has its own descriptor numbering pool. You can't freely pass descriptors between processes (and you can't steal them from other processes).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Jonny174 (18th February 2012)

  4. #3
    Join Date
    Apr 2011
    Location
    Russia
    Posts
    85
    Thanks
    2
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QProcess: Socket descriptor in argv[]

    Thanks for reply. I will do it with fork.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QProcess: Socket descriptor in argv[]

    There is another solution. Make your process read from its stdin and write to its stdout and intercept those channels in your server and forward the data read from the socket to the process's stdin and the data from stdout of the process to the socket.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 23
    Last Post: 17th April 2013, 09:52
  2. Replies: 2
    Last Post: 22nd May 2011, 21:31
  3. QApplication(argc, argv)
    By SWEngineer in forum Newbie
    Replies: 4
    Last Post: 26th April 2011, 12:36
  4. Socket Descriptor
    By ManuMies in forum Qt Programming
    Replies: 1
    Last Post: 17th March 2009, 09:42
  5. Watching a UNIX file descriptor
    By invictus in forum Newbie
    Replies: 1
    Last Post: 13th January 2009, 20:26

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.