Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-5153

Problem with QTcpServer or QTcpSocket

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P2: Important
    • None
    • 4.6.0
    • Network: Sockets

    Description

      t4id: 261373

      From mail-list:

      I'm having problems using the QTcpSocket in the Tower release. Initially it works fine, but generally after about ~450 requests (sometimes later, around 700 or even up to 1300) the applicartion stops responding. The incoming connection is seeing properly on my app, but the receiving end does not get a response.

      Any ideas what's going on?

      Below is an example app that illustrates the problem, modified from the http server example in in qt solutions. The example runs fine on other platforms.

      main.cpp
      	#include <QObject>
      	#include <QTcpServer>
      	#include <QTcpSocket>
      	#include <QStringList>
      	#include <QTextStream>
      	#include <QMessageBox>
      	#include <QApplication>
      	class SocketTest : public QTcpServer
      	{
      	    Q_OBJECT
      	public:
      	    SocketTest(QObject* parent = 0) : QTcpServer(parent) {
      	        listen(QHostAddress::Any, 8080);
      	    }
      	    void incomingConnection(int socket) {
      	        QTcpSocket* s = new QTcpSocket(this);
      	        connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));        
      	        connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
      	        s->setSocketDescriptor(socket);
      	    }
      	private slots:
      	    void readClient() {
      	        QTcpSocket* socket = (QTcpSocket*)sender();
      	        if (socket->canReadLine()) {
      	            QStringList tokens = QString(socket->readLine()).split(QRegExp("[ \r\n][ \r\n]*"));
      	            if (tokens[0] == "GET") {
      	                QTextStream os(socket);
      	                os.setAutoDetectUnicode(true);
      	                os << "HTTP/1.0 200 Ok\r\n"
      	                    "Content-Type: text/html; charset=\"utf-8\"\r\n"
      	                    "\r\n"
      	                    "<h1>Helllo, world!</h1>";
      	                socket->close();
      	                if (socket->state() == QTcpSocket::UnconnectedState) {
      	                    delete socket;
      	                }
      	            }
      	        }
      	    }        
      	    void discardClient() {
      	        QTcpSocket* socket = (QTcpSocket*)sender();
      	        socket->deleteLater();        
      	    }
      	};
      	 
      	 
      	#include "main.moc"
      	 
      	int main(int argc, char** argv) 
      	{
      	    QApplication app(argc, argv);
      	    SocketTest test(&app);
      	    QMessageBox box;
      	    box.setText("Exit");
      	    box.show();
      	    app.exec();    
      	}
      
      main.pro
      	 
      	TEMPLATE = app
      	QT += network
      	SOURCES = main.cpp
      	symbian {
      	TARGET.CAPABILITY="NetworkServices"
      	}
      

      I assume there is memory leak either in Qt or Open C which makes the socket to fail after certain amount of requests.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              earthdomain Earth Domain (Inactive)
              jasmcdon Jason McDonald (Closed Nokia Identity. Please assign to "macadder" instead) (Inactive)
              Votes:
              4 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes