PDA

View Full Version : QProcess: Socket descriptor in argv[]



Jonny174
18th February 2012, 12:28
Hi All!

How send socket descriptor in command prompt arguments on Linux without using fork function?
I try this:


void Server::incomingConnection( int handle )
{
...

QProcess *fork_process = new QProcess( this );
fork_process->setEnvironment( QProcess::systemEnvironment() );
fork_process->setProcessChannelMode( QProcess::MergedChannels );
fork_process->setWorkingDirectory( QCoreApplication::applicationDirPath() );

QStringList process_args;
process_args << "SD";
process_args << QString::number( handle );

fork_process->start( QCoreApplication::applicationFilePath(), process_args );

if (!fork_process->waitForStarted())
{
qDebug() << "fork_process Error: " << fork_process->errorString();

delete fork_process;
fork_process = 0;

return;
}

connect( fork_process, SIGNAL(finished(int,QProcess::ExitStatus)),
this, SLOT(processFinished(int,QProcess::ExitStatus)) );

...
}


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

wysota
18th February 2012, 12:33
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).

Jonny174
18th February 2012, 12:40
Thanks for reply. I will do it with fork.

wysota
18th February 2012, 12:42
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.