Browse Source

Restart idle timer on sending network response

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
ece92a886a
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 13
      src/base/http/connection.cpp
  2. 4
      src/base/http/connection.h

13
src/base/http/connection.cpp

@ -45,8 +45,18 @@ Connection::Connection(QTcpSocket *socket, IRequestHandler *requestHandler, QObj @@ -45,8 +45,18 @@ Connection::Connection(QTcpSocket *socket, IRequestHandler *requestHandler, QObj
, m_requestHandler(requestHandler)
{
m_socket->setParent(this);
// reset timer when there are activity
m_idleTimer.start();
connect(m_socket, &QIODevice::readyRead, this, [this]()
{
m_idleTimer.start();
read();
});
connect(m_socket, &QIODevice::bytesWritten, this, [this]()
{
m_idleTimer.start();
connect(m_socket, &QTcpSocket::readyRead, this, &Connection::read);
});
}
Connection::~Connection()
@ -56,7 +66,6 @@ Connection::~Connection() @@ -56,7 +66,6 @@ Connection::~Connection()
void Connection::read()
{
m_idleTimer.restart();
m_receivedData.append(m_socket->readAll());
while (!m_receivedData.isEmpty())

4
src/base/http/connection.h

@ -52,11 +52,9 @@ namespace Http @@ -52,11 +52,9 @@ namespace Http
bool hasExpired(qint64 timeout) const;
bool isClosed() const;
private slots:
void read();
private:
static bool acceptsGzipEncoding(QString codings);
void read();
void sendResponse(const Response &response) const;
QTcpSocket *m_socket;

Loading…
Cancel
Save