View Full Version : How to get out from waitForReadyRead(Timeout) blocking?
qmonkey
15th February 2011, 20:02
I have a client thread is blocked on QTcpSocket's waitForReadyRead(Timeout), other than receiving a message from server or reducing timeout length, how do I get out of the blocked state gracefully(basicly get out of the client waiting loop)?
Thanks in advance.
ars
15th February 2011, 21:32
Maybe you can use QIODevice::readyRead() signal instead of waitForReadyRead().
qmonkey
15th February 2011, 21:44
That's one option, but it requires a new design. I'm looking for a quick solution, if there is one:confused:
Thanks for the reply!
ars
15th February 2011, 22:01
What about (very quick and dirty)
bool dataAvailable = false;
QTime t;
t.start();
do
{
dataAvailable = waitForReadyRead(smallTimeout);
QApplication::processEvents();
}
while(!dataAvailable && (t.elapsed() < Timeout));
if(dataAvailable)
{
// process your data
}
else
{
// process timeout
}
Not a really nice way, but could work if you do not require precise timeout conditions.
qmonkey
16th February 2011, 14:43
ars,
That's not what I wanted. I want it stays blocked waiting for data, not timed out by itself, but have an option to get out at anytime.
drave
16th February 2011, 16:40
Its either waiting or it aint, you cant have it both ways. Close the socket your waiting on.
cheers
qmonkey
16th February 2011, 19:26
Look like non-blocking is the only way out. Thank you guys for the reply!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.