mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-25 09:18:54 -05:00
HttpServer: use settings structures in place of QSettings (4)
This commit is contained in:
parent
ef2f591bcd
commit
ab55400cc2
@ -5,15 +5,47 @@
|
||||
|
||||
#include "httpconnectionhandler.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httplistenersettings.h"
|
||||
|
||||
using namespace qtwebapp;
|
||||
|
||||
HttpConnectionHandler::HttpConnectionHandler(QSettings* settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration)
|
||||
: QThread()
|
||||
: QThread(), useQtSettings(true)
|
||||
{
|
||||
Q_ASSERT(settings!=0);
|
||||
Q_ASSERT(requestHandler!=0);
|
||||
this->settings=settings;
|
||||
this->listenerSettings=0;
|
||||
this->requestHandler=requestHandler;
|
||||
this->sslConfiguration=sslConfiguration;
|
||||
currentRequest=0;
|
||||
busy=false;
|
||||
|
||||
// Create TCP or SSL socket
|
||||
createSocket();
|
||||
|
||||
// execute signals in my own thread
|
||||
moveToThread(this);
|
||||
socket->moveToThread(this);
|
||||
readTimer.moveToThread(this);
|
||||
|
||||
// Connect signals
|
||||
connect(socket, SIGNAL(readyRead()), SLOT(read()));
|
||||
connect(socket, SIGNAL(disconnected()), SLOT(disconnected()));
|
||||
connect(&readTimer, SIGNAL(timeout()), SLOT(readTimeout()));
|
||||
readTimer.setSingleShot(true);
|
||||
|
||||
qDebug("HttpConnectionHandler (%p): constructed", this);
|
||||
this->start();
|
||||
}
|
||||
|
||||
HttpConnectionHandler::HttpConnectionHandler(HttpListenerSettings* settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration)
|
||||
: QThread(), useQtSettings(false)
|
||||
{
|
||||
Q_ASSERT(settings!=0);
|
||||
Q_ASSERT(requestHandler!=0);
|
||||
this->settings=0;
|
||||
this->listenerSettings=settings;
|
||||
this->requestHandler=requestHandler;
|
||||
this->sslConfiguration=sslConfiguration;
|
||||
currentRequest=0;
|
||||
@ -109,7 +141,7 @@ void HttpConnectionHandler::handleConnection(tSocketDescriptor socketDescriptor)
|
||||
#endif
|
||||
|
||||
// Start timer for read timeout
|
||||
int readTimeout=settings->value("readTimeout",10000).toInt();
|
||||
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings->readTimeout;
|
||||
readTimer.start(readTimeout);
|
||||
// delete previous request
|
||||
delete currentRequest;
|
||||
@ -173,7 +205,7 @@ void HttpConnectionHandler::read()
|
||||
{
|
||||
// Restart timer for read timeout, otherwise it would
|
||||
// expire during large file uploads.
|
||||
int readTimeout=settings->value("readTimeout",10000).toInt();
|
||||
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings->readTimeout;
|
||||
readTimer.start(readTimeout);
|
||||
}
|
||||
}
|
||||
@ -267,7 +299,7 @@ void HttpConnectionHandler::read()
|
||||
else
|
||||
{
|
||||
// Start timer for next request
|
||||
int readTimeout=settings->value("readTimeout",10000).toInt();
|
||||
int readTimeout = useQtSettings ? settings->value("readTimeout",10000).toInt() : listenerSettings->readTimeout;
|
||||
readTimer.start(readTimeout);
|
||||
}
|
||||
delete currentRequest;
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
namespace qtwebapp {
|
||||
|
||||
class HttpListenerSettings;
|
||||
|
||||
/** Alias type definition, for compatibility to different Qt versions */
|
||||
#if QT_VERSION >= 0x050000
|
||||
typedef qintptr tSocketDescriptor;
|
||||
@ -59,6 +61,7 @@ public:
|
||||
@param sslConfiguration SSL (HTTPS) will be used if not NULL
|
||||
*/
|
||||
HttpConnectionHandler(QSettings* settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration=NULL);
|
||||
HttpConnectionHandler(HttpListenerSettings* settings, HttpRequestHandler* requestHandler, QSslConfiguration* sslConfiguration=NULL);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~HttpConnectionHandler();
|
||||
@ -73,6 +76,7 @@ private:
|
||||
|
||||
/** Configuration settings */
|
||||
QSettings* settings;
|
||||
HttpListenerSettings* listenerSettings;
|
||||
|
||||
/** TCP socket of the current connection */
|
||||
QTcpSocket* socket;
|
||||
@ -98,6 +102,9 @@ private:
|
||||
/** Create SSL or TCP socket */
|
||||
void createSocket();
|
||||
|
||||
/** Settings flag */
|
||||
bool useQtSettings;
|
||||
|
||||
public slots:
|
||||
|
||||
/**
|
||||
|
@ -6,14 +6,16 @@
|
||||
#endif
|
||||
#include <QDir>
|
||||
#include "httpconnectionhandlerpool.h"
|
||||
#include "httplistenersettings.h"
|
||||
|
||||
using namespace qtwebapp;
|
||||
|
||||
HttpConnectionHandlerPool::HttpConnectionHandlerPool(QSettings* settings, HttpRequestHandler* requestHandler)
|
||||
: QObject()
|
||||
: QObject(), useQtSettings(true)
|
||||
{
|
||||
Q_ASSERT(settings!=0);
|
||||
this->settings=settings;
|
||||
this->listenerSettings=0;
|
||||
this->requestHandler=requestHandler;
|
||||
this->sslConfiguration=NULL;
|
||||
loadSslConfig();
|
||||
@ -21,6 +23,19 @@ HttpConnectionHandlerPool::HttpConnectionHandlerPool(QSettings* settings, HttpRe
|
||||
connect(&cleanupTimer, SIGNAL(timeout()), SLOT(cleanup()));
|
||||
}
|
||||
|
||||
HttpConnectionHandlerPool::HttpConnectionHandlerPool(HttpListenerSettings* settings, HttpRequestHandler* requestHandler)
|
||||
: QObject()
|
||||
{
|
||||
Q_ASSERT(settings!=0);
|
||||
this->settings=0;
|
||||
this->listenerSettings=settings;
|
||||
this->requestHandler=requestHandler;
|
||||
this->sslConfiguration=NULL;
|
||||
loadSslConfig();
|
||||
cleanupTimer.start(settings->cleanupInterval);
|
||||
connect(&cleanupTimer, SIGNAL(timeout()), SLOT(cleanup()));
|
||||
}
|
||||
|
||||
|
||||
HttpConnectionHandlerPool::~HttpConnectionHandlerPool()
|
||||
{
|
||||
@ -51,7 +66,7 @@ HttpConnectionHandler* HttpConnectionHandlerPool::getConnectionHandler()
|
||||
// create a new handler, if necessary
|
||||
if (!freeHandler)
|
||||
{
|
||||
int maxConnectionHandlers=settings->value("maxThreads",100).toInt();
|
||||
int maxConnectionHandlers = useQtSettings ? settings->value("maxThreads",100).toInt() : listenerSettings->maxThreads;
|
||||
if (pool.count()<maxConnectionHandlers)
|
||||
{
|
||||
freeHandler=new HttpConnectionHandler(settings,requestHandler,sslConfiguration);
|
||||
@ -66,7 +81,7 @@ HttpConnectionHandler* HttpConnectionHandlerPool::getConnectionHandler()
|
||||
|
||||
void HttpConnectionHandlerPool::cleanup()
|
||||
{
|
||||
int maxIdleHandlers=settings->value("minThreads",1).toInt();
|
||||
int maxIdleHandlers = useQtSettings ? settings->value("minThreads",1).toInt() : listenerSettings->minThreads;
|
||||
int idleCounter=0;
|
||||
mutex.lock();
|
||||
foreach(HttpConnectionHandler* handler, pool)
|
||||
@ -89,8 +104,8 @@ void HttpConnectionHandlerPool::cleanup()
|
||||
void HttpConnectionHandlerPool::loadSslConfig()
|
||||
{
|
||||
// If certificate and key files are configured, then load them
|
||||
QString sslKeyFileName=settings->value("sslKeyFile","").toString();
|
||||
QString sslCertFileName=settings->value("sslCertFile","").toString();
|
||||
QString sslKeyFileName = useQtSettings ? settings->value("sslKeyFile","").toString() : listenerSettings->sslKeyFile;
|
||||
QString sslCertFileName = useQtSettings ? settings->value("sslCertFile","").toString() : listenerSettings->sslCertFile;
|
||||
if (!sslKeyFileName.isEmpty() && !sslCertFileName.isEmpty())
|
||||
{
|
||||
#ifdef QT_NO_OPENSSL
|
||||
|
@ -45,6 +45,8 @@ namespace qtwebapp {
|
||||
@see HttpRequest for description of config settings maxRequestSize and maxMultiPartSize
|
||||
*/
|
||||
|
||||
class HttpListenerSettings;
|
||||
|
||||
class DECLSPEC HttpConnectionHandlerPool : public QObject {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(HttpConnectionHandlerPool)
|
||||
@ -57,6 +59,7 @@ public:
|
||||
@warning The requestMapper gets deleted by the destructor of this pool
|
||||
*/
|
||||
HttpConnectionHandlerPool(QSettings* settings, HttpRequestHandler* requestHandler);
|
||||
HttpConnectionHandlerPool(HttpListenerSettings* settings, HttpRequestHandler* requestHandler);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~HttpConnectionHandlerPool();
|
||||
@ -68,6 +71,7 @@ private:
|
||||
|
||||
/** Settings for this pool */
|
||||
QSettings* settings;
|
||||
HttpListenerSettings* listenerSettings;
|
||||
|
||||
/** Will be assigned to each Connectionhandler during their creation */
|
||||
HttpRequestHandler* requestHandler;
|
||||
@ -87,6 +91,9 @@ private:
|
||||
/** Load SSL configuration */
|
||||
void loadSslConfig();
|
||||
|
||||
/** Settings flag */
|
||||
bool useQtSettings;
|
||||
|
||||
private slots:
|
||||
|
||||
/** Received from the clean-up timer. */
|
||||
|
Loading…
Reference in New Issue
Block a user