Results 1 to 13 of 13

Thread: QHttp (internal bug?)

  1. #1
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Question QHttp (internal bug?)

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QHttp (internal bug?)

    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.

  3. #3
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QHttp (internal bug?)

    Yes, I use abort() but it doesn't solve the problem, that's the reason why I was trying closeConnection(), connection remains alive

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QHttp (internal bug?)

    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.

  5. #5
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QHttp (internal bug?)

    State after abort() has been called is QHttp::Connected

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QHttp (internal bug?)

    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.

  7. #7
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QHttp (internal bug?)

    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.

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QHttp (internal bug?)

    according to stateChanged(int), there is no connection
    Do mean you never get a connected state?
    Can you show your code?

  9. #9
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QHttp (internal bug?)

    It connects, but when connection is closed (status()), netstat tells its still active until the end of app.

    Qt Code:
    1. void frmMain::lastFmHandShake()
    2. {
    3. qDebug("lastFmHandShake()");
    4.  
    5. delete lfmBuffer;
    6. lfmBuffer = new QBuffer;
    7.  
    8. if (!lfmServer)
    9. lfmServer = new QHttp("post.audioscrobbler.com");
    10. else
    11. {
    12. lfmServer->disconnect();
    13. lfmServer->abort();
    14. }
    15.  
    16. connect(lfmServer, SIGNAL(done(bool)), this, SLOT(lastFmResolved(bool)));
    17. connect(lfmServer, SIGNAL(stateChanged(int)), this, SLOT(lastFmServerStatus(int)));
    18.  
    19. lfmServer->get(
    20. QString("/?hs=true&p=1.1&c=%1&v=%2&u=%3")
    21. .arg("fap")
    22. .arg("0.1")
    23. .arg(lfmUser),
    24. lfmBuffer);
    25. }
    26. /*
    27. void frmMain::lastFmServerStatus(int i)
    28. {
    29. switch (i)
    30. {
    31. case QHttp::Unconnected:
    32. qDebug("There is no connection to the host");
    33. break;
    34. case QHttp::HostLookup:
    35. qDebug("A host name lookup is in progress.");
    36. break;
    37. case QHttp::Connecting:
    38. qDebug("An attempt to connect to the host is in progress.");
    39. break;
    40. case QHttp::Sending:
    41. qDebug("The client is sending its request to the server.");
    42. break;
    43. case QHttp::Reading:
    44. qDebug("The client's request has been sent and the client is reading the server's response.");
    45. break;
    46. case QHttp::Connected:
    47. qDebug("The connection to the host is open, but the client is neither sending a request, nor waiting for a response.");
    48. break;
    49. case QHttp::Closing:
    50. qDebug("The connection is closing down, but is not yet closed. (The state will be Unconnected when the connection is closed.");
    51. break;
    52. }
    53. }
    54. */
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QHttp (internal bug?)

    and when does frmMain::lastFmHandShake() get called?

  11. #11
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QHttp (internal bug?)

    You can obtain complete source here

  12. #12
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QHttp (internal bug?)

    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:
    Qt Code:
    1. else
    2. {
    3. lfmServer->disconnect();
    4. lfmServer->abort();
    5. }
    To copy to clipboard, switch view to plain text mode 
    never gets called.

  13. #13
    Join Date
    Mar 2007
    Posts
    31
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: QHttp (internal bug?)

    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.

Similar Threads

  1. QHttp in thread (QT4)
    By maxpower in forum Qt Programming
    Replies: 15
    Last Post: 21st February 2007, 18:55
  2. QHttp internal error
    By LubosD in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2006, 09:57
  3. how to use QHttp inside QThread in Qt3
    By alusuel in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2006, 11:19
  4. QHttp related
    By whoops.slo in forum Qt Programming
    Replies: 12
    Last Post: 20th June 2006, 20:57
  5. Replies: 1
    Last Post: 1st March 2006, 11:43

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.