From: Ethan A M. <sf...@us...> - 2014-02-11 20:33:49
|
On Sunday, 09 February, 2014 16:57:36 sfeam wrote: > > And indeed if I change the timeout: > > > > --- a/src/qtterminal/qt_term.cpp > > +++ b/src/qtterminal/qt_term.cpp > > @@ -251,7 +252,7 > > > > // The QLocalSocket::waitForConnected does not respect the > > time out argument when the > > // gnuplot_qt application is not yet started. To wait for it, > > we need to implement the timeout ourselves > > - QDateTime timeout = QDateTime::currentDateTime().addMSecs(1000); > > + QDateTime timeout = QDateTime::currentDateTime().addMSecs(10000); > > do > > { > > qt->socket.connectToServer(server); > > > > it suddenly almost starts working. I'm saying almost because the first > > plot doesn't work, but the second one does. > > Hence my suspicion that timeouts < 1000msec are not working. > I suggest you do a global search and replace for timeouts and make > sure they are all >1000 msec. I think I have uncovered part of the problem, but I do not understand why it is failing. This loop: do { qt->socket.connectToServer(server); qt->socket.waitForConnected(200); // TODO: yield CPU ? } while(...) Does not work as intended. To see why, change it to this: qDebug() << "qt_connectToServer " << server; do { qt->socket.connectToServer(server); if (!qt->socket.waitForConnected(TIMEOUT)) qDebug() << qt->socket.errorString(); usleep(50000); } while(...) Regardless of the value of TIMEOUT, including -1 or blank, the waitForConnected returns immediately with an error: "QLocalSocket::connectToServer: Invalid name" Without the usleep() it spews hundreds or even thousands of these errors before fallling through to the rest of the code. The usleep reduces this to a manageable number of error reports. So the first connection attempts always fail, even under linux, and the failure is immediate. Why is it an invalid name? I don't know. How does it eventually succeed? I don't know that either. Since TIMEOUT is ignored this is becomes a CPU-burning loop, which is what Mojca originally reported. The usleep should fix that, and a large enough manual timeout as in QDateTime timeout = QDateTime::currentDateTime().addMSecs(30000); may in fact be necessary. But it would be nice to understand the real reason why the initial connection attempts fail, because maybe we can test and wait on that condition directly and avoid the useless loop here. Ethan |