Note that there are some explanatory texts on larger screens.

plurals
  1. POQTcpSocket / QTcpServer memory management / server crash
    text
    copied!<p>I am designing and making a server that should be able to handle about 100+ hits per second. The information I am getting from the server is just the HTTP header. Based on the information from the header, it will query a database(different thread) for some information and send the final information back to the QTcpServer which create an output string, and send back a HTTP Response. I am having a big problem with this that I cannot debug. My code look similar to this:</p> <pre><code>TCPInterface::TCPInterface(QObject *parent): QTcpServer(parent) { //start listening for tcp traffic on port 80 listen(QHostAddress::Any, 80); connect(this,SIGNAL(sendInfo(QTcpSocket*, QString *)), databaseThread, SLOT(recieveInfo(QTcpSocket*, QString*))); connect(databaseThread, SIGNAL(sendToTCPSend(QTcpSocket *, QString *)), this, SLOT(TCPSend(QTcpSocket*, QString*))); } </code></pre> <p>`</p> <pre><code>void TCPInterface::incomingConnection(int socket) { QTcpSocket *s = new QTcpSocket(this); connect(s, SIGNAL(readyRead()), this, SLOT(readClient())); //connect(s, SIGNAL(disconnected()), this, SLOT(discardClient())); s-&gt;setSocketDescriptor(socket); } </code></pre> <p>`</p> <pre><code>//void TCPInterface::discardClient() //{ //QTcpSocket* socket = (QTcpSocket*)sender(); //socket-&gt;deleteLater(); //} </code></pre> <p>`</p> <pre><code>void TCPInterface::readClient() { QTcpSocket* socket = (QTcpSocket*)sender(); QString header; while(socket-&gt;canReadLine()) { header += socket-&gt;readLine(); } emit sendInfo(socket, headerInfo); } </code></pre> <p>`</p> <pre><code>void databaseThread::recieveInfo(QTcpSocket* socket, QString* headerInfo) { QString*outputInfo = getDatabaseInfo(headerInfo); emit sendToTCPSend(socket, outputInfo); } </code></pre> <p>`</p> <pre><code>void TCPInterface::TCPSend(QTcpSocket* socket, QString* outputInfo); { QString response = "HTTP/1.0 200 Ok\r\n"; response += "Content-Type: text/html; charset=\"utf-8\"\r\n"; response += "\r\n" + *outputInfo + "\n"; if(socket-&gt;isWritable() &amp;&amp; socket-&gt;isOpen()) { socket-&gt;write(response.toAscii()); } //socket-&gt;disconnectFromHost(); socket-&gt;close(); delete headerInfo; } </code></pre> <p>I having one main problem which I have an idea what it is, but cannot find a solution to fix it.</p> <p>My problem is my memory is constantly increasing as I get more hits. I am sure the cause of this is my QTcpSockets are never being deleted, since I am just closing them. However when I don't use close, and use disconnectFromHost and disconnected/discardClient slot/signal my server will crash with heavy traffic(no message or anything so I am not sure of the exact reason of the crash). Has anyone run into this problem before? Any ideas at all.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload