QtWebApp
httpconnectionhandler.h
Go to the documentation of this file.
1 
6 #ifndef HTTPCONNECTIONHANDLER_H
7 #define HTTPCONNECTIONHANDLER_H
8 
9 #ifndef QT_NO_SSL
10  #include <QSslConfiguration>
11 #endif
12 #include <QTcpSocket>
13 #include <QSettings>
14 #include <QTimer>
15 #include <QThread>
16 #include "httpglobal.h"
17 #include "httprequest.h"
18 #include "httprequesthandler.h"
19 
20 namespace stefanfrings {
21 
23 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
24  typedef qintptr tSocketDescriptor;
25 #else
26  typedef int tSocketDescriptor;
27 #endif
28 
30 #ifdef QT_NO_SSL
31  #define QSslConfiguration QObject
32 #endif
33 
52 class DECLSPEC HttpConnectionHandler : public QObject {
53  Q_OBJECT
54  Q_DISABLE_COPY(HttpConnectionHandler)
55 
56 public:
57 
64  HttpConnectionHandler(const QSettings* settings, HttpRequestHandler* requestHandler,
65  const QSslConfiguration* sslConfiguration=nullptr);
66 
68  virtual ~HttpConnectionHandler();
69 
71  bool isBusy();
72 
74  void setBusy();
75 
76 private:
77 
79  const QSettings* settings;
80 
82  QTcpSocket* socket;
83 
85  QThread* thread;
86 
88  QTimer readTimer;
89 
91  HttpRequest* currentRequest;
92 
94  HttpRequestHandler* requestHandler;
95 
97  bool busy;
98 
100  const QSslConfiguration* sslConfiguration;
101 
103  void createSocket();
104 
105 public slots:
106 
111  void handleConnection(const tSocketDescriptor socketDescriptor);
112 
113 private slots:
114 
116  void readTimeout();
117 
119  void read();
120 
122  void disconnected();
123 
125  void thread_done();
126 };
127 
128 } // end of namespace
129 
130 #endif // HTTPCONNECTIONHANDLER_H
Alias for QSslConfiguration if OpenSSL is not supported.
The request handler generates a response for each HTTP request.
This object represents a single HTTP request.
Definition: httprequest.h:37
qintptr tSocketDescriptor
Alias type definition, for compatibility to different Qt versions.