-
Notifications
You must be signed in to change notification settings - Fork 158
/
qhttpserverconnection.hpp
87 lines (69 loc) · 2.87 KB
/
qhttpserverconnection.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/** HTTP connection class.
* https://github.com/azadkuh/qhttp
*
* @author amir zamani
* @version 2.0.0
* @date 2014-07-11
*/
#ifndef QHTTPSERVER_CONNECTION_HPP
#define QHTTPSERVER_CONNECTION_HPP
///////////////////////////////////////////////////////////////////////////////
#include "qhttpfwd.hpp"
#include <QObject>
///////////////////////////////////////////////////////////////////////////////
namespace qhttp {
namespace server {
///////////////////////////////////////////////////////////////////////////////
/** a HTTP connection in the server.
* this class controls the HTTP connetion and handles life cycle and the memory management
* of QHttpRequest and QHttpResponse instances autoamtically.
*/
class QHTTP_API QHttpConnection : public QObject
{
Q_OBJECT
public:
virtual ~QHttpConnection();
/** set an optional timer event to close the connection. */
void setTimeOut(quint32 miliSeconds);
/** forcefully kills (closes) a connection. */
void killConnection();
/** optionally set a handler for connection class.
* @note if you set this handler, the newRequest() signal won't be emitted.
*/
void onHandler(const TServerHandler& handler);
/** returns the backend type of the connection. */
TBackend backendType() const;
/** returns connected socket if the backend() == ETcpSocket. */
QTcpSocket* tcpSocket() const;
/** returns connected socket if the backend() == ELocalSocket. */
QLocalSocket* localSocket() const;
/** creates a new QHttpConnection based on arguments. */
static
QHttpConnection* create(qintptr sokDescriptor, TBackend backendType, QObject* parent) {
QHttpConnection* conn = new QHttpConnection(parent);
conn->setSocketDescriptor(sokDescriptor, backendType);
return conn;
}
signals:
/** emitted when a pair of HTTP request and response are ready to interact.
* @param req incoming request by the client.
* @param res outgoing response to the client.
*/
void newRequest(QHttpRequest* req, QHttpResponse* res);
/** emitted when the tcp/local socket, disconnects. */
void disconnected();
protected:
explicit QHttpConnection(QObject *parent);
explicit QHttpConnection(QHttpConnectionPrivate&, QObject *);
void setSocketDescriptor(qintptr sokDescriptor, TBackend backendType);
void timerEvent(QTimerEvent*) override;
Q_DISABLE_COPY(QHttpConnection)
Q_DECLARE_PRIVATE(QHttpConnection)
QScopedPointer<QHttpConnectionPrivate> d_ptr;
friend class QHttpServer;
};
///////////////////////////////////////////////////////////////////////////////
} // namespace server
} // namespace qhttp
///////////////////////////////////////////////////////////////////////////////
#endif // #define QHTTPSERVER_CONNECTION_HPP