PDA

View Full Version : QHttp (internal bug?)



fear
15th March 2007, 09:09
Hi,
my app is unstable due to QHttp behaviour, I've noticed that connection to http server is still alive despite the fact I've called QHttp::closeConnection(), even when I delete QHttp object, netstat still shows active connection, it is closed when I quit my app. Maybe it's because I use my own QHttpRequestHeader (along with post() method) and I missed something,
Thanks.

high_flyer
15th March 2007, 10:34
Well, lets see what the docs say:


The function does not block and returns immediately. The request is scheduled, and its execution is performed asynchronously. The function returns a unique identifier which is passed by requestStarted() and requestFinished().

When the request is started the requestStarted() signal is emitted. When it is finished the requestFinished() signal is emitted.

If you want to close the connection immediately, you have to use abort() instead.

fear
15th March 2007, 11:15
Yes, I use abort() but it doesn't solve the problem, that's the reason why I was trying closeConnection(), connection remains alive :(

high_flyer
15th March 2007, 11:22
hmm...
Try reading state(), or read it in a slot connected to stateChanged() after you call abort().
This might hint about where the porblem could be.

fear
15th March 2007, 11:47
State after abort() has been called is QHttp::Connected :confused:

high_flyer
15th March 2007, 12:01
did you call it or did you use a slot?
Connect the signal stateChanged() to a slot, in which you read state().
The you can see exactly the flow of the QHttp objects states.
I don't think abort() initiated a connected() state, it only means the abort() was not yet executed by QHttp, we need to try and find out why.
I guess your QHttp object is very busy, and just needs a lot of time to process its event loop.
It would help if you could show your code, not only where you are aborting, but also where you send packeted to the QHttp object.
Also did you pay attention to this:


This class provides two different interfaces: one is the QNetworkProtocol interface that allows you to use HTTP through the QUrlOperator abstraction. The other is a direct interface to HTTP that allows you to have more control over the requests and that allows you to access the response header fields.

Don't mix the two interfaces, since the behavior is not well-defined.

fear
15th March 2007, 12:29
Ok, according to stateChanged(int), there is no connection, netstat claims there is active connection until I exit from my app. I use only QHttp.

high_flyer
15th March 2007, 12:58
according to stateChanged(int), there is no connection
Do mean you never get a connected state?
Can you show your code?

fear
15th March 2007, 13:13
It connects, but when connection is closed (status()), netstat tells its still active until the end of app.



void frmMain::lastFmHandShake()
{
qDebug("lastFmHandShake()");

delete lfmBuffer;
lfmBuffer = new QBuffer;

if (!lfmServer)
lfmServer = new QHttp("post.audioscrobbler.com");
else
{
lfmServer->disconnect();
lfmServer->abort();
}

connect(lfmServer, SIGNAL(done(bool)), this, SLOT(lastFmResolved(bool)));
connect(lfmServer, SIGNAL(stateChanged(int)), this, SLOT(lastFmServerStatus(int)));

lfmServer->get(
QString("/?hs=true&p=1.1&c=%1&v=%2&u=%3")
.arg("fap")
.arg("0.1")
.arg(lfmUser),
lfmBuffer);
}
/*
void frmMain::lastFmServerStatus(int i)
{
switch (i)
{
case QHttp::Unconnected:
qDebug("There is no connection to the host");
break;
case QHttp::HostLookup:
qDebug("A host name lookup is in progress.");
break;
case QHttp::Connecting:
qDebug("An attempt to connect to the host is in progress.");
break;
case QHttp::Sending:
qDebug("The client is sending its request to the server.");
break;
case QHttp::Reading:
qDebug("The client's request has been sent and the client is reading the server's response.");
break;
case QHttp::Connected:
qDebug("The connection to the host is open, but the client is neither sending a request, nor waiting for a response.");
break;
case QHttp::Closing:
qDebug("The connection is closing down, but is not yet closed. (The state will be Unconnected when the connection is closed.");
break;
}
}
*/

high_flyer
15th March 2007, 13:24
and when does frmMain::lastFmHandShake() get called?

fear
15th March 2007, 13:29
You can obtain complete source here (http://falf.sourceforge.net/) :eek:

high_flyer
15th March 2007, 14:02
sorry I really don'T have the time.
It would help if you'd explaint it.
My guess is, that you are calling frmMain::lastFmHandShake() only ones, so the part:


else
{
lfmServer->disconnect();
lfmServer->abort();
}

never gets called.

fear
16th March 2007, 08:18
It's not so simple but in this single case I can say these two lines inside {} are never called. Last state after GET request is unconnected and the problem is netstat claims connection is still active. Calling abort() or closeConnection() gives no result.